Jump to content

Run JavaScript on Safari

Recommended Posts

Is there a way to run a specific JavaScript through Alfred in the safari window you're looking at?


The script address is 

It is.

Link to post

Safari lets you run JS in a tab via AppleScript: tell application "Safari" to do JavaScript "alert('script!')" in front document


It expects proper JavaScript, though, not a javascript: URI


Link to post

You need to remove the javascript: scheme and URL-decode it:

const q=escape(location.href);location.href='https://papago.naver.net/website?locale=ko&source=auto&target=ko&url='+q;

The full AppleScript to run that JS in the active tab is therefore:

tell application "Safari" to do JavaScript "const q=escape(location.href);location.href='https://papago.naver.net/website?locale=ko&source=auto&target=ko&url='+q;" in front document


Edited by deanishe
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...