Here are the options that I explored and experimented with:
Option 1: Use Login Elements
This is the method I used. This is very easy to do from a bash file by adding the following line to your postfloc.
defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -array-add '{Path="/Applications/Your Application.app";}'
Note. You donβt even have to worry about adding duplicates if you reinstall the application. The loginwindow process removes duplicates when they are read.
I tested this on 10.5, 10.6 and 10.7
@noa says this does not work for a mountain lion (10.8), has not been personally confirmed.
Option 2: LaunchAgent
The only consequences of using the launch agent are:
- Your application does not appear in the Login Elements list, so the user really needs to know what they are doing to get rid of it.
- The user cannot complete the application process without starting: launchctllload / Library / LaunchAgents / com.your.package.plist
Here is the code you could use to create the launch agent in your bash file:
cat > /Library/LaunchAgents/com.your.application.agent.plist << EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.your.application.agent</string> <key>ProgramArguments</key> <array> <string>/Applications/Your Application.app/Contents/MacOS/Your Application</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> EOT
Option 3. Compiling Obj-c Code to Binary
I have never finished this approach. This seems to be the approach Novell is taking. Essentially, you will create a basic application that calls the libraries referenced by this solution: How do I open the application when I log in?
Other
Did not try this, but according to this post, if you want it to work with a tiger, you need to use AppleScript ..? I cannot confirm or refute this, but thought that this link might be relevant. Editing Mac OS X login items in Objective-C via AppleScript
blak3r
source share