Mac OS X and Firefox – opening a new tab

There is a bug in Firefox on Mac OS X that opening a new tab from the command line (using the -new-tab option) doesn’t work – it tries to open a new copy of Firefox and fails:

Skjermbilde 2016-07-24 kl. 13.42.22

This seems to be a known issue that won’t be fixed (Bug 393645) – apparently something to do with the way that Mac applications communicate.

The workaround for this is an Applescript. The script below checks if Firefox is running. If it isn’t, it launches with the requested URL. Otherwise it activates Firefox, and fires the keystrokes to do the job.

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” to activate

tell application “System Events”
keystroke “t” using {command down}
keystroke item 1 of argv & return
end tell
end if
end run

To run the script, enter the following on the command line:

osascript ffnewtab.scpt <url>

July 24, 2016   Tags: apps, macosx

Leave a Reply