Tuesday, May 21, 2013
  • Index
  •  » Code Exchange
  •  » FireFari: Open Firefox if it's already open; Safari if it isn't.

#1 2007-11-02 04:13:04 pm

girasquid
Member
From: 127.0.0.1
Registered: 2007-10-14
Posts: 12
Website

FireFari: Open Firefox if it's already open; Safari if it isn't.

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.

Code:

-- 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.

Last edited by girasquid (2007-11-02 04:14:20 pm)


Filed under: safari, System, firefox

Offline

 
  • Index
  •  » Code Exchange
  •  » FireFari: Open Firefox if it's already open; Safari if it isn't.

Board footer

Powered by FluxBB

[ Generated in 0.020 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)