I am able to add new login items (for my user in the Accounts preference pane) without trouble, but unable to later delete them. None of the different variations of “delete login item” works. The code works fine in Panther 10.3.9; I’m assuming it broke in Tiger (10.4.2) but does anyone know a workaround? Here’s my code:
on addLoginItem(itemPath)
dbg("adding login item " & itemPath)
try
set itemPOSIXPath to (POSIX path of itemPath)
tell application "System Events"
try
delete (every login item whose name is "myGreatApp")
end try
make login item at end with properties {path:itemPOSIXPath, hidden:false, name:"myGreatApp"}
end tell
end try
end addLoginItem
on removeLoginItem(itemPath)
try
set itemPOSIXPath to (POSIX path of itemPath)
tell application "System Events"
try
delete (every login item whose name is "myGreatApp")
on error
try
delete (login item whose path is itemPOSIXPath)
on error
if last character of itemPOSIXPath is "/" then
set alternatePath to text 1 thru -2 of itemPOSIXPath
delete (login item whose path is alternatePath)
end if
end try
end try
end tell
end try
end removeLoginItem
Browser: Safari 412.2
Operating System: Mac OS X (10.4)