It’s a fairly simple process to script adding and deleting login items using applescript. You can save these scripts as applications and send them out to users. Then they can run it themselves and add or remove a login item. You can have applications open on login or volumes mount on login.

Adding a login item

For adding a login item we’ll use the example of mounting a remote volume. I usually find that it works best to actually mount the item first and then add the login item. For this example we’ll assume we’re connecting to an SMB share named “home” on a Windows server.

[codesyntax lang=”applescript” lines=”no”]
mount volume “smb://server.example.com/home”
tell application “Finder”
--check to see if the volume mounted
if disk “home” exists then
display dialog “Success”
--this “tell” statement makes the actual login item
tell application “System Events”
make login item at end with properties {path:”/Volumes/home”, kind:volume}
end tell
else
--if it doesn’t work let the user know
display dialog “Oops! This problem happened:” & return & errmsg
end if
end tell
[/codesyntax]

So, in the example above we mount the server share first. Then, we check to see if it’s actually there. If so we tell the user we’ve succeeded with a dialog box and make the login item. If not we let them know there was a problem and display the error message so they can tell tech support.

Notice the “kind” section of that line. You need to tell it what you’re adding (a volume, an application, etc.).

Deleting a login item

Deleting a login item is even easier.

[codesyntax lang=”applescript” lines=”no”]
tell application “System Events”
--Find out what login items we have
get the name of every login item
--see if the item we want exists. If so then delete it
if login item “home” exists then
delete login item “home”
else
display dialog “That login item doesn’t exist”
end if
end tell
[/codesyntax]

We check to see what login items we have. If the one we want to delete exists we go ahead and nuke it.