I have been struggling with a problem of trying to get an application I install to start up when the user logs in. I finally found a solution via applescript:
tell application "System Events"
-- We delete existing login item, in case app has moved
try
delete login item "MyApp"
end try
make new login item at end with properties {path:"/Applications/Test/MyApp", hidden:false}
end tell
I stole this from another application. However, looking at it, I have no idea how you would come up with this script on your own.
The command “make new login item” is the key here, but how would you find out about this? Is there a source with all the differant commands you can give?
What I really need is to modify this script so it adds a startup for ALL users, not just the current user. I have found out ways to do this outside of apple script, however these always cause my app to run as root, not as the current user. I do not want my app to run as root, and this applescript method is the only way I have found to do this.
The scripting dictionary for System Events has a breakdown of all the available commands. The dictionary for other applications will have their own commands and properties as well. That, plus Apple’s provided documentation on their developer website should have everything you need and more.
As for setting login items for multiple users… You’d have to run as a privileged user (i.e. root) to manage that, even using Applescript. The login items for each user are protected from editing by other users.
Assuming you are using the Script Editor, the dictionary for any application you have is opened by selecting “Library” under the “Window” menu. If the application you want isn’t already in the window that appears, click the plus button and add it. If the application isn’t scriptable (doesn’t hava an AppleScript Dictionary), you’ll be warned, no harm done. You can remove it with the minus button. If you don’t have the application yet or want a pdf copy of its dictionary, there are lots of them to be found on site in MacScripter’s “Scriptable Apps” section.