How to Run a Shell Script with Mac App Sandbox Enabled?

混江龙づ霸主 提交于 2019-12-06 07:42:15

Why would you want to sandbox such a powerful App it in the first place? Do you want to modify defaults and killall for specific other apps (somehow possible) or for "all that exist on the machine"?

If for specific other apps, why not do it without shell? For defaults write use com.apple.security.temporary-exception.shared-preference.read-write and add the domains you'd like to modify (eg. com.apple.DigitalColorMeter) and use CFPreferencesSetValue()

For killall use com.apple.security.temporary-exception.apple-events and run an Applescript / send AppleEvents to terminate specific processes.

Scripts can be run from the NSApplicationScriptsDirectory directory when the app is Sandboxed.

NSURL *scriptsDirectory = [[NSFileManager defaultManager] URLForDirectory:NSApplicationScriptsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];

So how does a user grant access for an application that wants to run scripts?

The mechanism is surprisingly simple: your application can only run scripts from a specific folder in the user’s account. The only way scripts can get into that folder is if the user copies them there. Essentially, OS X gives you a read-only view of what’s in those scripts.

https://www.objc.io/issues/14-mac/sandbox-scripting/

A great article on the subject ^^^

Anno2001

If you have a good reason you can kill applications like this:

How can I terminate my app in a helper app with sanboxing enabled?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!