blog/templates/permalink.htm - header
Hauptseite
   10.05.2022 23:21:12

Starting Firefox with a different profile via an Icon

I recently found myself in need to easily start Firefox with a different profile. On Linux this might have been really simple, as you can easily create a script to start firefox and hand over a parameter to load the right profile. In Mac this proofed to be a little bit more complicated, especially if you want to have an icon to click and do the same.

After searching on the Internet for some time and experimenting with Automator, I realised there are ways to do it, but most had some sort of limitation or quirk. In some cases Firefox started, but in the background. In other cases the cog from the Automator workflow kept running in the menu bar while the profiled firefox was running. Other suggestions on the net went es far as copying the firefox application container and modifying it to do the thing.

I decided that this was not good enough. Apple should be able to support this usecase and allow me to do the following:

  • Have an application with icon available that could be used via Dock, Finder and Spotlight.
  • Don't have the cog from Automator running in the icon bar while running.
  • Have the application at hand immediately after starting in the foreground.

In the end the solution is not that complicated. But none of the websites mentioned this specific solution. So I decided to document it here.

Create the application

  • Start Automator. You can find it via Spotlight (Command + Space). Or by going into the Application-Folder.
  • Create a new "Application" in Automator (File > New).

    New Application
    New Application
  • Search for the Action "Run Shell Script" and drag it into the Workflow editor.

    Run Shell Script
    Run Shell Script
  • Enter the following command into the Run Shell Script-module:

    exec open -n -a Firefox.app --args -P <name-of-your-profile> "$@" > /dev/null 2>&1
    Command
    Command
  • Store the application e.g. to your personal ~/Application-folder with any name you like.

Change the icon

There are several tutorials on the net on how to change the Icon of any application. Just for completeness I will describe it here:

  • Find your newly created application in Finder. Right click and open "Get Info".

    Get Info
    Get Info
  • An info window opens.

    Info Window
    Info Window
  • The icon at the top showing the current applications icon, is clickable.

    Application icon
    Application icon
  • Now just select an icon you want to use, copy it to the clipboard, click on the application icon and just paste. You have a new icon. A place to find icons on your Mac is /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/. You can use Finders "Go To Folder" functionality to get there.

This just changes the icon of the application starter. The running application will still keep its usual icon.

How does it work

open is a fantastic little application that can be used to execute a lot of things from the command line on the Mac. In this case we replace our running shell (which we initialise with the Run Shell Command) using exec to instead run open. We ask open to start the application even if it is already running (-n) and and tell it to run the Firefox.app-Application -a (this prevents us to search for the firefox executable inside the Firefox.app-Container, which suggest several sources on the net). We then tell open to accept parameters for the application in the rest of the arguments. -P <name-of-your-profile> tells Firefox to start with the specified profile instead of the default profile. And finally "$@" just takes all command line arguments eventually handed to this application to Firefox, so that you could use this application to also start firefox with additional commands.

> /dev/null 2>&1 is just a redirection of the output of the application to /dev/null, the trash for command line output. 2>&1 also redirect error messages to the trash.

The result is as follows:

  • When starting this newly created application a shell gets started which executes open. While this happens the cog will appear in the menu bar.
  • As soon as open finishes to trigger the application, it ends, and the workflow also finishes, which removes the cog from the menu bar.
  • Firefox.app is started (even if it already is running anywhere else) accepting the additional parameters, which leads to a Firefox with a specific profile ready to be used.

Obviously this approach is not limited to start Firefox with additional parameters, but can be used for any application that accepts command line arguments to change its behaviour (e.g. blender).

Open questions

I would love to also have a seperate icon in the Application Switcher. But I assume for this I actually would require a modified copy of Firefox. Or does somebody have a hint for me whether this is possible?



Erstellt von Jerri | Kategorie: apple