2
votes

I want to launch myapp.app during login time and it should work for all users.

I tried with osascript which launch only for a user who run that command .

/usr/bin/osascript -e "tell application \"System Events\" to make a new login item with properties {path : "Path/myapp.app" hidden:false name:"myapp"} at end "

I ran this log-in as a guser .So it launches during login of only guser .

And even i tried with sudo defaults write /Library/Preferences/loginwindow AutoLaunchedApplicationDirectory -array-add '{ "Path" ="path1" ; "Hide"="0";}'

When path1=myapp.app it didnt worked When path1=myapp.app/Contents/MacOS/myapp it is launching for all users but even a terminal window is launching along with the application .

I have a shell script from that i have to some command that launches cocoa app for all users login time. Please help .

1
For information about why sudo defaults write doesn't work, see stackoverflow.com/questions/9483959/osx-10-8-loginitemspaulmelnikow

1 Answers

0
votes

You can use LSSharedFileList API.
Take a look at How can a Cocoa application add itself as a global login item? and Register as Login Item with Cocoa?

Take a look at Technical Note TN2083(Global Login Item)

A global login item is a login item that is launched when any user logs in. Installing a global login item is roughly equivalent to installing that login item for all users on the system: every time a user logs in, loginwindow launches that user's login items and all global login items.