Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have the following javascript that searches the current site (very handy)


I am a launchbar user, but launchbar will not open this javascript bookmark.

Can i create an applescript that runs the javascript bookmark (in chrome, which is my default browser)

Have tried:-

tell application "Google Chrome"    
    execute javascript "javascript:Qr=prompt('Search%20Site%20for','');if(Qr)location.href=''+encodeURIComponent(window.location.hostname)+'+'+escape(Qr"
end tell

but nothing happens...

share|improve this question
up vote 6 down vote accepted

There are three problems with the script you posted, and one of them may be just a problem that was caused when you pasted the code into your question.

Starting from the beginning: You need to tell Chrome where to do the JavaScript, like this:

tell application "Google Chrome" to tell active tab of front window to execute javascript "your script"

That will run the script in the current tab of the first window you opened (AFAIK, you can't yet get the active tab of the active window).

Next, you don't want that javascript: prefix; Chrome knows it's JavaScript.

Finally, you're missing a paren at the very end of your line. Again, I'm not sure if this is just a copy problem, but it's something to be aware of.

Making the above changes, I have this code:

tell application "Google Chrome" to tell active tab of front window to execute javascript "Qr=prompt('Search%20Site%20for','');if(Qr)location.href=''+encodeURIComponent(window.location.hostname)+'+'+escape(Qr)"

...which works.

share|improve this answer
you absolute beauty!!! you wont believe how much i enjoy using this script, such a timesaver. – rapscalli Jul 25 '11 at 18:42
@rapscalli if this solved the problem, don't forget to accept the answer by clicking the check mark next to it. :) – Nathan Greenstein Jul 25 '11 at 22:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.