Why not directly set the application with SMLoginItemSetEnabled? Why do we need to use a helper application?īecause the SMLoginItemSetEnabled function works only with executables stored in the Contents/Library/LoginItems directory of the bundle. Note: Before calling the SMLoginItemSetEnabled function, first register with Launch Services by calling the LSRegisterURL function with the URL for the helper application bundle.” The Helper Application This function can be used to manage any number of helper applications. This function returns true if the requested change has taken effect otherwise, it returns false. Pass false to terminate the helper application and indicate that it should no longer be launched when the user logs in. Pass true to start the helper application immediately and indicate that it should be started every time the user logs in. It takes two arguments, a CFStringRef containing the bundle identifier of the helper application, and a Boolean specifying the desired state.
Use the SMLoginItemSetEnabled function (available in Mac OS X v10.6.6 and later) to enable a helper application. Set either the LSUIElement or LSBackgroundOnly key in the ist file of the helper application’s bundle.
“Applications can contain a helper application as a full application bundle, stored inside the main application bundle in the Contents/Library/LoginItems directory. “Instead, use the SMLoginItemSetEnabled function along with the LSRegisterURL function, as described in “Adding Login Items Using the Service Management Framework” in Daemons and Services Programming Guide.” In the “App Sandbox Design Guide”, Apple says:
For example, you cannot use the function LSSharedFileListInsertItemURL.” The Solution Recommended by Apple “With App Sandbox, you cannot create a login item using functions in the LSSharedFileList.h header file.
Now, with the file permissions enforcements, accessing the shared file list of login items is forbidden.
This technique works well until App Sandbox has been introduced. If we want to run a dockless application at login and we are using Mac OS X 10.5 or later, we can add login items using a shared file list with LaunchServices/LSSharedFileList.h API.