Skip to content

Instantly share code, notes, and snippets.

@technosophos
Last active May 22, 2023 08:06
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save technosophos/c85b66f3dbb3fa2aac695ecc6e9d2609 to your computer and use it in GitHub Desktop.
Save technosophos/c85b66f3dbb3fa2aac695ecc6e9d2609 to your computer and use it in GitHub Desktop.
Open a Tab in Firefox on macOS with AppleScript
# To run:
# osascript firefox-open-tab.applescript http://technosophos.com
#
# References:
# https://support.mozilla.org/en-US/questions/1130718
# https://stackoverflow.com/questions/3645763/how-do-i-instruct-applescript-to-open-a-new-firefox-window-with-a-link
on firefoxRunning()
tell application "System Events" to (name of processes) contains "firefox"
end firefoxRunning
on run argv
if (firefoxRunning() = false) then
do shell script "open -a Firefox " & (item 1 of argv)
else
tell application "Firefox"
activate
open location item 1 of argv
end tell
end if
end run
@technosophos
Copy link
Author

$ alias ot='osascript $CODE/firefox-open-tab.applescript'
$ ot http://technosophos.com

@linonetwo
Copy link

linonetwo commented May 9, 2019

Why the execution is so slow? It takes 2-8s to complete, not instantly as I expect.

@linonetwo
Copy link

I tried to minify it, but still very slow:

on run
	tell application "Firefox"
		activate
		tell application "System Events" to keystroke "t" using command down
	end tell
end run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment