How to add my application to StartupItems from inside the application itself ?
24/02/05 08:53
I want to offer to the user the possibility to add my application to the StartupItems folder as an option in the installation procedure and later in the Preferences: how to do that in a save and portable way ?
You can use AppleScript from inside your application (using NSAppleScript):
set app_path to path to me
tell application "System Events"
if "MY_APP_NAME" is not in (name of every login item) then
make login item at end with properties {hidden:false, path:app_path}
end if
end tell
tell application "System Events"
if "MY_APP_NAME" is in (name of every login item) then
delete (every login item whose name is "MY_APP_NAME")
end if
end tell
Replace MY_APP_NAME by your application's name...
set app_path to path to me
tell application "System Events"
if "MY_APP_NAME" is not in (name of every login item) then
make login item at end with properties {hidden:false, path:app_path}
end if
end tell
tell application "System Events"
if "MY_APP_NAME" is in (name of every login item) then
delete (every login item whose name is "MY_APP_NAME")
end if
end tell
Replace MY_APP_NAME by your application's name...