I’m new to AS (just started looking into it yesterday). I’d like to open a webpage in Safari, keystroke tab three times, then keystroke return. The return will press a button that submits my username and password (remembered by Safari) to log me into a site.
From beginning to end, how would this be done?
Well since ya asked so nice and all
set this_url to "your url here"
tell application "Safari"
activate
if not (exists document 1) then
make new document at the beginning of documents
else
tell application "System Events" to tell process "Safari" to click menu item "New Tab" of menu "File" of menu bar 1
end if
set URL of document 1 to this_url
end tell
tell application "System Events"
tell process "Safari"
delay 2
keystroke tab
keystroke tab
keystroke tab
keystroke return
end tell
end tell
Wonderful, thank you. I did tweak it a bit to make it work:
… tell process “Safari”
delay 10
keystroke tab
delay 1
keystroke tab
delay 1
keystroke tab
keystroke return …
Sometimes the page takes longer to open, hence the delay 10. Also, if a Safari page is open, it gives an error: “System Events got an error: NSReceiverEvaluationScriptError: 4 (1)” - I may play around with the script to see if it can work with a page already opened.
Thanks so much! (This AS stuff may become an addiction).