Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the executable in an OS X Application Bundle

Tags:

macos

firefox

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?

like image 613
Rob Avatar asked Apr 08 '09 16:04

Rob


People also ask

What is the extension for an executable in Mac?

In macOS, the Mach-O file format is the native executable format.

How do I change unidentified developer preferences on Mac?

To change which apps can open on your Mac, choose Apple menu > System Settings, click Privacy & Security in the sidebar, then go to Security. (You may need to scroll down.) To change your security settings, see Protect your Mac from malware.


1 Answers

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

like image 130
Nicholas Riley Avatar answered Oct 22 '22 18:10

Nicholas Riley