Starting app (hidden) from command line...

I admit this is probably an elementary unix question, but I'm pretty ignorant on unix. What would I write in a command line (it'll be a one-line script, actually) to start up a Mac OS application. (.app) and have it hide itself when it starts? (like whatever login must do when it starts up login items with the "hide" checkbox marked.)
(let's suppose the path to the application is /Applications/TheAppIWant.app )

Ted Lee
Minnetonka, MN

Mini, G4 desktop, and powerbook G4, Mac OS X (10.4)

Posted on Apr 7, 2008 2:00 PM

Reply
5 replies

Apr 7, 2008 5:38 PM in response to Mark Jalbert

Should I repost it in an Applescript area? The reason I phrased it as a unix question is that I have a 3rd-party application that I'd like to have automatically (gracefully) quit when the machine goes to sleep and be started again, with its single window hidden, when the system wakes up. There is a third-party package available that will trigger shell scripts on sleep and wake; I don't know if there's anything that will trigger an applescript at those times. The unix "killall" and "open" commands do what I want to do, except of course the open doesn't hide the app. (If you need further explanation, the app is badly behaved when put to sleep -- the system won't wake -- but it will serve its purpose fine if it's quit and restarted.)

Ted Lee
Minnetonka, MN

Apr 7, 2008 5:39 PM in response to Theodore Lee

You can't really launch a GUI app hidden.

You basically have three options:

1) launch the application frontmost (as if you double-clicked it)
2) launch the application in the background (behind the current application)
3) launch the application and then hide it.

The first two options can be achieved via the open command:

open -a TheAppIWant
open --background -a TheAppIWant


the --background option tells the app to open behind the current app.

To get #3 I think you have to revert to AppleScript after you open the app:

open --background -a TheAppIWant
osascript -e 'tell application "System Events" to set visible of application process "TheAppIWant" to false'

Apr 7, 2008 8:05 PM in response to Camelot

Thanks -- it looks like the "--background" option is only in Leopard (it doesn't work in Tiger and isn't listed in the man page) but all the other pieces work when entered in a terminal window. I haven't yet put all the pieces together to get actual shell scripts written and tied into the SleepWatcher package, but I'm sure they'll work.

Ted Lee
Minnetonka, MN

Apr 8, 2008 8:04 AM in response to Theodore Lee

p.s. -- in some other thread someone pointed out that using "launch" in an Applescript will start the app in the background. It appears all that means is that it's not the front window -- it came up behind some windows but in front of others. (I'm sure something here says that.) Not a big deal, since I'll be hiding it as soon as it comes up once I get the whole sript written.

Ted Lee
Minnetonka, MN

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Starting app (hidden) from command line...

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.