APP='Disk Utility' ; pgrep -qx "$APP" || open -g -j -a "$APP"
Note what the -g and -j arguments to open will do:
-g Do not bring the application to the foreground.
-j Launches the app hidden.
Remove one or both if you do not want those features.
Also note that some apps do not respect -g and -j. These apps are to be considered to be of poor quality (often "cross-platform" apps which have not been given sufficient attention for their Mac port).
Send [cmd+n] if no windows open
I'm not sure how to do this one without Keyboard Maestro, but in Keyboard Maestro it would be simple:
I already have a script doing the first three (see below), all in the same script.
As the logic behind what to do increases in complexity, it's easier to do this in a proper programming language than to expand on it with Applescript, whose syntax eludes me from time to time.
Also, the "send [cmd+n] if no windows open" feature would be possible to create within btt (I think?) perhaps with a conditional activation group, it's a lot of work to do this for every single App I've customized (which is a long and ever increasing list)
I'm pretty sure this functionality would be of use for many more than myself, and deserves to be native features of such a great app as BTT
The script
I'm not sure exactly, but I think I got the zist of this script from Brett Terpstra.
set appName to "Typora"
set startIt to false
tell application "System Events"
if not (exists process appName) then
set startIt to true
else if frontmost of process appName then
set visible of process appName to false
else
set frontmost of process appName to true
end if
end tell
if startIt then
tell application appName to activate
end if
First feedback: It appears the triggers that already existed that used the "Show/Hide application" feature stopped working after this update; I had to re-edit this step in order to get it working again. I'm not sure how I can make a reproducible test case of this scenario on the drop of a hat.
I will test this out thorougly once the update with cmd+n is released, will set off some time to tinker with my setup again at that time.
btw:
I just realized how I ended up with this awesome setup.
I bought "BetterSnapTool" and had some snall issues with it, and emailed you.
Got a free one year (I think) license for BTT !
After using ONLY the feature for moving/resizing windows with a regular mouse for over 6 months, I realized I wanted to duplicate the "hyper key" functionality I've been reading so much about.
Installed Karabiner_Elements, and enabled the hyper key
The rest is history!
Thanks for an awesome piece of software.