Trying to decide between a LaunchAgent or LoginItem, but also looking for a way of getting a launch agent registered with `launchd` without having to go through creating files and running a command line tool.
This is for a mac app, that is installed by dragging the app from the downloads folder. ie there isn't an installer. Currently the app isn't sandboxed but we are thinking of moving to sandboxing the app so we don't want to create a problem for ourselves in the near future.
Currently I have created a LaunchAgent for the application that works and the agent communicates with the application with XPC using the `NSXPC...` related API. The LaunchAgent also works as a LoginItem communicating via XPC with the application.
For this to work and for the LaunchAgent to work immediately it is not only necessary to copy the launch agent plist file to `~/Library/LaunchAgents` but to also run `launchctl load ...`*. This of course will be problematic for sandboxing. Is there a better or recommended approach that does not require creating plist files in `~/Library/LaunchAgents` and running the command line tool.
A restriction for LoginItems is that for `SMLoginItemSetEnabled` to work the application needs to be in the `/Applications` folder. This potentially creates unnecessary work for CS and for engineers debugging and testing. This would be fine for an app in the App Store. There also seems more control over the behaviour of a LaunchAgent via its plist than just calling the `SMLoginItemSetEnabled` function with YES or NO. For example enabling means the LoginItem stays alive all the time and we don't need that behaviour.
The readme.txt file for the example loginitem says that the LoginItem and application must be sandboxed. https://developer.apple.com/library/archive/samplecode/AppSandboxLoginItemXPCDemo/Listings/ReadMe_txt.html#//apple_ref/doc/uid/DTS40012292-ReadMe_txt-DontLinkElementID_3
I have got the login item working without the app and login item being sandboxed. Is that unintended behaviour and really a LoginItem should not be considered for non-sandboxed apps or is that information just wrong?
* I have tried reading the man page for `launchctl` so that I don't have to use the deprecated `load` subcommand but it is not clear from the man page what is the equivalent of just calling `launchctl load ~/Library/LaunchAgents/XXX.com.companyname.agentname`