I use this script to open a URL in a new tab but I would like it to open in the current tab instead. Is there a way to do this?
tell application "Firefox"
open location "http://www.yubnub.org"
end tell
Firefox's Applescript support appears not very existent.
Try this workaround using System Events and key strokes.
tell application "Firefox"
activate
set the clipboard to "http://www.yubnub.org"
tell application "System Events"
keystroke "l" using {command down}
keystroke "v" using {command down}
key code 36 -- return key
end tell
end tell
I upvoted the accepted answer, it's great and led me to my solution, but using the clipboard to enter the URL seems unnecessary when you can simply send the URL via keys
tell application "Firefox"
activate
tell application "System Events"
keystroke "l" using {command down}
keystroke "http://www.yubnub.org"
key code 36 -- return key
end tell
end tell
A line shorter, more understandable, and doesn't have the unwanted side effect of overwriting your clipboard.
Related
I have this script that I have been working on to clear out my Caches and application support files I will skip to the part that I need help with;
tell application "System Events"
keystroke "o" using {command down}
delay 0.5
keystroke delete using {command down}
end tell
When the script gets to the keystroke delete using {command down} I get the error message;
error "System Events got an error: Can’t continue using." number -1708
How can I improve?
You use not keystroke, but the related key code to access special keys.
tell application "System Events"
key code 51 using {command down}
end tell
See full reference of key codes here.
I have tried using the code;
tell application "Google Chrome"
activate
end tell
tell application "System Events"
keystroke 124 using {command down, option down}
end tell
is there anything wrong with this script because command option arrow normally switches tabs
tell application "Google Chrome"
activate
end tell
tell application "System Events"
key code 124 using {command down, option down}
end tell
how do I tell applescipt to hit alt?
I want to press simultaneously alt+s
This code does not work:
tell application "System Events" to keystroke "s" using alt
Thanks in advance
The answer is
tell application "System Events" to keystroke "s" using option down
or
tell application "System Events" to keystroke "s" using {option down}
You can use the list option if you want to simulate multiple keys like command down/control down/option down/shift down.
Easily found in the scripting dictionary of System Events
Enjoy, Michael / Hamburg
I got error; Can’t get button "save" of process "TextEdit".
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke "s" using {command down}
click button "save"
end tell
I was also tring to include like "of window 1" still I can't get this working. Any help will be much appreciated. thanks
why not just talk to the app directly ?
tell application "TextEdit"
tell document 1 to save
end tell
if you must use the GUI you need the correct hierarchy ( but it is best to talk to the app directly)
activate application "TextEdit"
tell application "System Events"
tell process "TextEdit"
keystroke "s" using {command down}
delay 1
click button "Save" of sheet 1 of window 1
end tell
end tell
I am trying a simple Keystroke command to Show All Bookmarks in Safari 5.0.2 but it is not working -
tell application "Safari" to activate
tell application "System Events"
keystroke "B" using {option down, command down}
end tell
end
Can anyone suggest me where I may be wrong?
Thanks,
Miraaj
Try a little 'b':
tell application "Safari" to activate
tell application "System Events"
keystroke "b" using {option down, command down}
end tell
The big B translates to Shift+B.