Easily run a script on login in the background

May 31, '05 08:25:00AM

Contributed by: itistoday

This hint is for those that wish to run an AppleScript or shell script every time on login, but want it to happen quietly in the background without appearing in the dock.

Open up ScriptEditor in the Applications folder and paste in this code. Then save this AppleScript as an Application Bundle to some location. Go to this location and control-click on the script and choose "Show Package Contents" and go into Contents -> Resources -> Scripts. Drop your shell script in there (mine is called script.sh; make sure to edit the first line of the AppleScript to reflect the script's name). Finally, to make the whole thing invisible, open up the Info.plist file inside of the Contents folder of the AppleScript application. Right after the very first line, paste this in:

<key>NSUIElement</key>
<string>1</string>
Save the plist file and quit the editor. Now test your script by double-clicking on the script application. Apple seems to have some weird bug that will sometimes still cause it to appear in the dock. If this happens, simply duplicate (command-D) the script application and the duplicate should work. Finally, drop this script app into your Login Items in System Preferences, and you're set to go. Thanks to Ryan for help with this and this old hint for the posix_path() function.

[robg adds: I haven't tested this one...]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050517210406483