How to launch another process in sandbox on Mac?

浪子不回头ぞ 提交于 2019-12-03 12:59:49
rudy

There are very few conditions under which you'll be able to launch another application and have the desired outcome. com.apple.security.temporary-exception.files.absolute-path.read-write doesn't gain you anything with regard to LaunchServices so you can remove that entitlement.

As a sandboxed application you are fairly limited in what you can actually sub-launch, this is an intentional behavior as launching another application is technically a violation of the sandbox model. the ways available to you are:

  1. include an XPC Service in your application and have launchd launch it for you
  2. you can run an application via NSTask, which will cause this application to inherit your sandbox when launched
  3. you can launch an application by name, though from what i've seen this generally only works if the application is in your /Applications folder, i.e. -[NSWorkspace launchApplication:]
  4. you can launch an application that encloses your app, but only if you've been SMLoginItemSetEnabled()

I'd say the osascript call works because its doing roughly the same as -[NSWorkspace launchApplication:]. none of the LS calls that accept bundle identifiers or absolute/relative paths are going to work.

Use osascript

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