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:
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
then
# if running, hide it
osascript -e 'tell application "Finder"' -e 'set visible of process "Maps" to false' -e 'end tell'
else
# if not running, open hidden
open -a "Maps" -j
fi
Hey @cdthomer, I am running this script and other solutions for the Todoist app on mac and can't seem to get it to work properly:
The application /Applications/Todoist.app cannot be opened for an unexpected reason, error=Error Domain=NSOSStatusErrorDomain Code=-600 "procNotFound: no eligible process with specified descriptor" UserInfo={_LSLine=388, _LSFunction=_LSAnnotateAndSendAppleEventWithOptions}
This is the output when I try to run the entire command or just the open -a command with -j in the terminal.
This is the text script I'm using:
# determine if app is running
if pgrep -x "Todoist" > /dev/null
then
# if running, hide it
osascript -e 'tell application "Finder"' -e 'set visible of process "Todoist" to false' -e 'end tell'
else
# if not running, open hidden
open -a "Todoist" -j
fi
Do you know what may be wrong, or steps to take in order to find out for myself?
I’m not familiar with that error, and I don’t have that app for testing, but it looks like it can’t find the application process to launch it. Can you change the app name to something simpler, like Maps, and get it to work?
I just had a stubborn Qt application that refuses to reliably hide or stay in the background with the shell open -a <App> -j (or -g) command.
The thing that finally works – so far – is the combination of AppleScript’s run + immediately setting visible of the process to false:
tell application "<StubbornApp>"
if it is not running then
run
end if
end tell
tell application "System Events"
if application process "<StubbornAppProcess>" exists then
set visible of application process "<StubbornAppProcess>" to false
end if
end tell
I found this thread when looking for a way to open up an app in the background. Executing Shell Script with open -a Safari -j is simple and does the trick.
However I am facing an issue with Apps which name consists of multiple words. In this case the error message suggests that the script is looking for a file instead of an app. I am experiencing this with Find My for example but want it to work with Logi Options+. I tried to group the name with ' and " but both did not work. Do you have an idea?
This issue doesn't actually have anything to do with spaces in names. Instead, it has to do with some trickery by the Logitech folks: The name of the app is actually logioptionsplus, despite what you see in Finder.
open -a logioptionsplus -j should work; it did here in testing.
You can find any app's "real" name by selecting it in Finder then pressing ⌘-I to open the Get Info window. Look in the Name & Extension section for the name you need to reference when trying to launch the app in Terminal.
Alternatively, ls -al /Applications in Terminal will show every app's actual name.
(Technically, this is done by specifying a display name somewhere in the app's package—typically this can be used for localization, which appears to be how Logitech has done it; they set the display name in the language folders within the app bundle.)