Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sandboxed Mac app does not always launch automatically using SMLoginItemSetEnabled()

Tags:

macos

cocoa

I have a very strange issue with a sandboxed Mac app I'm developing. One requirement is that the user should have the possibility to launch the app when the system starts. For this, I'm using SMLoginItemSetEnabled() as described on http://blog.timschroeder.net/2012/07/03/the-launch-at-login-sandbox-project/.

When the user starts the app for the first time and enables this option, I can see an entry is being added to launchctl by using launchctl list. When I reboot the system, the app is not being started. More strange is the fact that the entry found using launchctl list has disappeared. However, a similar entry is still available in /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist with key Disabled being false.

When I start the app manually and again set the option to start automatically, the entry is again available in launchctl list. When I reboot the system the app is being launched automatically. Concluding, for some reason SMLoginItemSetEnabled() only works the second time I run the app. Therefor it looks similar to this issue: https://stackoverflow.com/questions/16354295/sandbox-app-with-loginitems-only-work-after-second-app-launch. However, no solution is provided.

https://stackoverflow.com/questions/16354295/sandbox-app-with-loginitems-only-work-after-second-app-launch

like image 926
Niels Mouthaan Avatar asked Sep 10 '13 06:09

Niels Mouthaan


People also ask

How do I use sandbox app on Mac?

Select the target of your macOS app in the Targets list. Click the Signing & Capabilities tab in the project editor. Locate the App Sandbox capability. Use each option's drop-down menu to choose None, Read Only, or Read/Write, depending on your app's requirements.

Can you use sandbox on Mac?

Overview. App Sandbox provides protection to system resources and user data by limiting your app's access to resources requested through entitlements. To distribute a macOS app through the Mac App Store, you must enable the App Sandbox capability.

Are Mac App Store apps sandboxed?

App Sandbox is an access control technology provided in macOS, enforced at the kernel level. It is designed to contain damage to the system and the user's data if an app becomes compromised. Apps distributed through the Mac App Store must adopt App Sandbox.


1 Answers

If you're like me, you probably had extra copies (generated by Xcode, etc) laying around that seem to confuse LaunchServices.

I wrote a post about it here: Login Items in macOS 10.11 and newer

But the short version is, use lsregister -dump to find all copies that LaunchServices knows about, remove them, then use lsregister -kill to reset the LaunchServices database when you're done.

like image 81
Devin Avatar answered Sep 21 '22 15:09

Devin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!