I do a lot of web development on my Mac. And when I’m doing it, I like to use Firefox - it’s got some great add-ons that just make it a lot easier. However, I use Safari for browsing. I’ve also got my mouse set up so that middle-click opens Safari, and if I’m already in Safari it opens a new tab. However, when I’m debugging with Firefox, I’m using Firefox; I’d rather have middle-click open Firefox. And so, this script was born.
-- check frontmost application; if it's Safari, we don't want to switch
set f_most to path to frontmost application as text
if f_most contains "Safari" then
-- we want to open a new tab in safari
tell application "System Events"
tell application "Safari" to activate
keystroke "t" using {command down}
end tell
else if f_most contains "Firefox" then
-- Firefox is the frontmost application; open a new tab
-- open a new tab in Firefox
tell application "System Events"
tell application "Firefox" to activate
keystroke "t" using {command down}
end tell
else
-- check if Firefox is open
tell application "System Events" to set ffopen to exists process "firefox-bin"
if ffopen then
-- If Firefox is open(debugging something), switch to it
activate application "Firefox"
else
-- Otherwise, just use Safari
activate application "Safari"
end if
end if
To set it all up, I created a Quicksilver Trigger on ctrl+f(figured it wouldn’t be in use anywhere) being released(so it doesn’t screw up the keystrokes), and set up my mouse to send the keystroke ctrl+f when the wheel button is pressed.
I’m not sure if anyone else will need(or even use) this, but here it is if anyone wants to. Knock yourselves out.