tags:

views:

755

answers:

2

I would like to run a script before Firefox starts & after it quits. In Ubuntu I do this by creating a new shortcut that calls my function first, then calls the firefox command, then calls my last function. Since the firefox command blocks until the application quits, my last function is called immediately after the process ends.

However, in OS X I cannot do this as nicely because I end up with two icons on the dock. One for my script turned into an application & another for the Firefox application. I would prefer to just have one dock icon & to not break Firefox updates.

My current solution is to rename both MacOS/firefox{,-bin} to be prefixed with 'real-" and then name my shell script "firefox-bin". This works, but I am pretty sure that the next time firefox tries to update itself I am toast.

I have tried changing the "CFBundleExecutable" property in the bundle's Info.plist file to be my script, but that doesn't work.

Can anyone offer any other suggestions?

A: 

Use an Automator workflow if available on your version of Mac OS.

dirkgently
When you launch an application it always creates an icon on the dock. I would prefer there only be one so as not to be confusing.I mentioned that I already have an application version of my script and I don't like that method.
Rob
@Rob: Thanks for the clarification. I was confused (I didn't see that you don't two icons at _runtime_).
dirkgently
@dirkgently: np, I think your solution is the only one that I am going to be able to go with. But I am still hoping some guru will come by with a few dollops of knowledge for me.
Rob
+1  A: 

Create a regular application bundle but set LSUIElement on it, so the script application's icon is hidden from the dock, and include Firefox inside the bundle.

A simple way of doing this is with Platypus. Configure Platypus as follows:

  • Click "Parameters". Check the "Set $1 to path to application" checkbox, so your script can reference files inside the bundle.

  • Check "Runs in background"—this sets LSUIElement for you.

  • In the list of "Files and folders to be bundled with application into the Resources folder", drop Firefox.

  • Change Output to "None" so your log messages go to the system console.

  • Drop Firefox's icon file (firefox.icns) on the "Custom Icon" well.

  • Change "App Name" to Firefox.

For a script that looks something like this:

#!/bin/sh
echo before >&2
$1/Contents/Resources/Firefox.app/Contents/MacOS/firefox-bin
echo after >&2

you get output like:

4/8/09 1:16:33 PM [0x0-0x801801].net.sabi.PlatypusScript[76610] before 
4/8/09 1:16:35 PM firefox-bin[76613] Database load time: 0.373 (717 objects) 
4/8/09 1:16:35 PM [0x0-0x801801].net.sabi.PlatypusScript[76610]
2009-04-08 13:16:35.699 firefox-bin[76613:10b] Database load time: 0.373 (717 objects) 
4/8/09 1:16:57 PM [0x0-0x801801].net.sabi.PlatypusScript[76610] after

If your users launch Firefox in other ways, such as with URL handlers and by opening HTML files, you'll instead need to use a native application, which can pass the appropriate Apple Events through to Firefox, and add the appropriate URL and file handler information to the Info.plist. (aemreceive is a convenient Python wrapper for Apple Event reception.)

Nicholas Riley
exactly what I was looking for, I just needed the bit about how to hide an icon from the dock. Danke!
Rob
An issue with this solution is that you cannot see the Firefox menu bar anymore. I found a better one above.
Rob