I need a way to add an application to the Login Items from a postflight script which is run as part of my installer. It needs to work on 10.5+. Preferably, it would work in a bash script. My application already requires administrative rights.

The approach I found here: https://stackoverflow.com/questions/4912212/mac-os-login-items-with-arguments seemed to be on the right track (included below)... but didn't work when I tried it on command line and I'm not sure how to make it install for All Users or if I need to add logic to check if it's already added to startup items before calling this code.

/usr/bin/osascript -e "tell application \"System Events\" to make new login item with properties { path: \"$1\", hidden:false } at end"

I suspect I could also do something with a launchd. But, I'm not sure which approach is the best practice for compatibility across versions.


If you don't mind a bit of reading, I'd suggest starting with Apple Technical Note TN2083: Daemons and Agents.

I haven't tested it, but I believe the easiest way to do what you want is via a launchd agent. That essentially involves dropping a plist file in /Library/LaunchAgents. A nice side benefit of this is that you could overwrite the same file there as many times as you like, and you shouldn't get multiple instances of your item (per user).

Something like:

    cat > /Library/LaunchAgents/com.serverfault.myapp.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">

The other possibility is a global login item. From that technical note mentioned above, I gleaned:

  • A global login item is a login item that is launched when any user logs in.
  • In Mac OS X 10.5 and later you can install a global login item using the shared file lists interface to Launch Services [API].
  • On earlier systems, you can install a login item [not a global login item] by sending Apple events to the System Events process. [So perhaps this no longer works reliably as of 10.5?]
  • Prior to Mac OS X 10.5 there is no supported way to install a global login item. [Wow! That's crazy.]

I believe that a lot of applications (prior to launchd in 10.5) used to manipulate the loginwindow.plist file directly. Unfortunately, a lot of them did it incorrectly – I can't tell you how many half-XML-half-binary-all-broken loginwindow.plist files I've seen.


Fission is pretty spot on.

There are some additional details on adding to login items from bash in the following stackoverflow post:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.