2

I use an Applescript to open a Javascript prompt for YubNub in Safari. Occasionally I use a search scope more often like "ebay" ect and I would like the Yubnub command already typed in the prompt so I can just type my search. I have tried the following script to type "ebay" in the prompt and it only shows an empty prompt. Any help would be appreciated. Thanks.

the script:

    tell application "Safari"
do JavaScript          
              "javascript:Qr=prompt('','');if(Qr)location.href='http://www.yubnub.org/parser/parse?         command='+escape(Qr)" in current tab of first window
    end tell
     delay 0.3
    tell application "System Events" to key code 14
    tell application "System Events" to key code 11
    tell application "System Events" to key code 0
    tell application "System Events" to key code 16

1 Answer 1

1

It's the same issue as I described in this question. Basically when you open the prompt from applescript, the whole applescript pauses until you dismiss the prompt. Same as the other question. Read that to get the full explanation. As such you could do this...

set searchTerm to "ebay"

do shell script "/usr/bin/osascript -e 'delay 1' -e 'tell application \"System Events\" to keystroke \"" & searchTerm & space & "\"' > /dev/null 2>&1 &"

tell application "Safari"
    activate
    set newTab to make new tab in window 1
    set current tab of window 1 to newTab
    do JavaScript "javascript:Qr=prompt('','');if(Qr)location.href='http://www.yubnub.org/parser/parse?         command='+escape(Qr)" in current tab of first window
end tell
Sign up to request clarification or add additional context in comments.

9 Comments

Thank you. That is exactly what I was trying to do.
any chance you would know how to get the above script to open it in a new window. I have tried for a few hours with no success.
I added the code to create a new tab in the current window, so your search will occur in that. Good luck. Also, please mark my post as the answer to your question by checking it... if it does in fact answer your question.
Sure it's possible. The trick is it's not called a window. It's a document. In the script just replace the 2 lines about the tab with "make new document".
I replaced "the set newTab to make new tab in window 1 set current tab of window 1 to newTab" with "make new document" and it just opens it in the same window.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.