Making a UI application invisible

This is probably quite a well-known tip, but could potentially be quite useful…

If you want to run an OS X application (specifically a Mach-O application – this trick isn’t supported by CFM applications) as a “daemon”, that is to say with no presence in the Dock and no visible graphical interface, it is possible to do so using a LaunchServices key in that application’s .plist file. There are two LaunchServices keys pertaining to running a program in the background, namely LSBackgroundOnly and LSUIElement. There is a brief discussion as to the difference between them here, although it doesn’t reach a brilliant conclusion…

In Apple terminology, setting LSBackgroundOnly to 1 creates a “faceless background application” whereas doing the same for LSUIElement causes an application to run as an “agent application”. As I understand it from Apple’s descriptions, an agent application is likely to want to present a user interface, but not appear in the Dock or the Force Quit window (the Dock itself, for example.) A faceless background application, however, should never need to present a UI at all.

However, if you want to spy on someone by, for example, installing a VNC server on their machine (not that I’d recommend it – that’d be highly illegal!), either LaunchServices key will hide the program from the Dock. So how do you set the keys for a specific application? I reckon the easiest way to do this is to use the defaults system, as follows:

$ defaults write /Applications/MyBackgroundApp/Contents/Info LSBackgroundOnly 1

This turns on the LSBackgroundOnly key to 1 for “MyBackgroundApp” (which will need to be relaunched to see the change.) Note that this will NOT work if the “Info” file in the packege has its normal “.plist” extension. You can see the addition of the new key by running

$ defaults read /Applications/MyBackgroundApp/Contents/Info

and change it back by running

$ defaults delete /Applications/MyBackgroundApp/Contents/Info LSBackgroundOnly

or

$ defaults write /Applications/MyBackgroundApp/Contents/Info LSBackgroundOnly 0

depending on how covert you need to be!

It appears, in my limited testing, that keyboard input is out of the question if an application is run in this manner when it wasn’t intended to be. As such, I recommend configuring all of the necessary settings for your program before setting either of these keys, otherwise you’ll end up not being able to type anything, which is clearly quite a handicap…

That is all.

Leave a Reply

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