Pragmatism in the real world

Activating rather than relaunching a menu bar app on macOS

One very minor thing that’s been bugging me since macOS Sequoia came out is that if you launch an app that lives in your menu bar, but also has a hidden Dock icon a second time, then the Dock icon will re-appear.

This happens to me a lot because I use Alfred to launch apps and also to bring an app to the front. This works because opening a running app will bring it to the foreground. You can test this using the Terminal with the open -a command if you want to.

I’ve used this workflow for years with the Harvest app. Harvest lives in my menu bar and can be accessed using the mouse. However, I tend to just open it again with Alfred which opens the main window which is anchored to the menu bar icon and then press space to stop the current timer or cmd+n to enter the details to start a new one.

Since Sequoia, I’ve noticed that when I use Alfred to open Harvest’s main window, the Harvest icon reappears on my Dock. I don’t want this, so I wrote an Alfed Workflow to fix it.

Alfred Workflow

The workflow consists of two blocks: a Keyword input and an AppleScript action.

Alfred harvest workflow.

The Keyword input block simply responds to the word “Harvest” as that’s what I type:

Alfred harvest keyword input.

Then, to either start Harvest, or activate it, I use some AppleScript:

tell application "System Events"
    if not (exists process "Harvest") then
        tell application "Harvest" to launch
    else
        tell application "Harvest" to activate
    end if
end tell

AppleScript remains one of the harder languages I write and I have to look things up every time, but at least LLMs make this easier. Once written, it’s quite easier to see what it does. The magic is that with this script we activate it rather than launch it once running.

In Alfred, it looks like this:

Alfred harvest applescript.

Training Alfred

That’s it. All I needed to do then was continually use Alfred with variations of “H”, “Ha”, “Har”, etc to train it to put my new “Open Harvest” action at the top of the list.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *