Launch shell script on login in Mac OS (OS X)

bash, macos, shell

Solution

You can't just place plain scripts in that folder. You need a "specialized bundle" how Apple calls it, basically a folder with your executable, and a .plist configuration. And you should put it in /Library/StartupItems since /System/Library/StartupItems/ is reserved for the operating system. Read all about it here:

https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpsystemstartup/chapters/StartupItems.html

Also note that the whole stuff is marked as deprecated technology. And that Apple is suggesting the use of launchd. There is an example how to set it up here:

https://superuser.com/questions/229773/run-command-on-startup-login-mac-os-x

Problem

I have this shell script `Test.sh`: ``` #! /bin/bash FILE_TO_CHECK="/Users/test/start.txt" EXIT=0 while [ $EXIT -eq 0 ]; do if [ -f "$FILE_TO_CHECK" ] then /usr/bin/java -jar myapp.jar EXIT=1 else sleep 30 fi done ``` I need to start this script automatically after login. So I put it inside a folder `Test` in `/System/Library/StartupItems/` When I reboot the Mac, nothing happens after I log in. Any clue? I also tried `Automator`, but with the same result: the java program is not running.

Original source

Related problems