Help Needed: Launching Apps in Background

What I'm Trying to Do

I'm trying to launch apps in the background without them popping up on the main screen and causing a havoc.

This applies to Todoist, Cron, Spotify, Bitwarden, and Spotify.

What I've Tried / What Actually Happens

When I test the action, it runs by itself, but for some reason the macro does not reach the point where it's supposed to resize, minimize, or close the app. Here's the macro I've been using:

Position App Windows.kmmacros (44 KB)

Any help would be greatly appreciated!

Pause until app is running by itself is useless in a launch scenario.

Most apps show as running long before you can affect their UI.

So you have to combine is running with something like menu-path exists or front-window exists, before you start trying to work with the app.

Keyboard Maestro doesn't support launching apps in the background.

To do this you can use the shell:

open -a Calculator -g

Or AppleScript:

tell application "Calculator"
   if it is not running then
   end if
end tell

I love this method and use it quite a bit myself...

For @szfkamil , if you want to open the app hidden, you can use the -j flag instead of the -g flag.

open -a Calculator -j

Open an application hidden.kmmacros (2.1 KB)

Macro screenshot (click to expand/collapse)


For posterity’s sake, I recently discovered that the command open -a ${app_name} -j only works if the app is not currently running. If it’s already running, it opens it visible. Here’s a workaround (using Maps as an example) to ensure that the app is either opened hidden, or if running, hide it.

# determine if app is running
if pgrep -x "Maps" > /dev/null
	# if running, hide it
	osascript -e 'tell application "Finder"' -e 'set visible of process "Maps" to false' -e 'end tell'
	# if not running, open hidden
	open -a "Maps" -j
1 Like