如何在Mac上的沙箱中启动另一个进程? [英] How to launch another process in sandbox on Mac?

查看:753
本文介绍了如何在Mac上的沙箱中启动另一个进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Mac上的Sandbox中通过LSOpenApplication()启动另一个自己的应用程序。

I'd like to launch another own application by LSOpenApplication() in Sandbox on Mac.

当然,我在com.apple.security

Of course, I added a row into 'com.apple.security.temporary-exception.files.absolute-path.read-write' in an entitlements file for launching.

但是,在启动时,控制台会抛出一个错误,该错误是不允许的允许进程xxxx启动foo.app,因为它以前没有被用户启动。
在手动启动过程后可以无错启动。

However, when launching, console spat out an error which is Not allowing process xxxx to launch "foo.app" because it has not been launched previously by the user. It is able to launch without errors after launched the process manually once.

即使以前未启动,我如何启动该进程?
这与沙盒没有关系吗?

How can I launch the process even if not launch previously? Is this no relation with sandboxing?

推荐答案

很少有条件可以启动另一个应用程序并具有所需的结果。 com.apple.security.temporary-exception.files.absolute-path.read-write不会向您提供有关LaunchServices的任何信息,因此您可以删除该权利。

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. 在您的应用程序中包含XPC服务,并为您启动它

  2. 您可以通过NSTask运行应用程序,这将导致此应用程序在启动时继承您的沙箱

  3. 您可以按名称启动应用程序,一般只有当应用程序在您的/ Applications文件夹中时,即 - [NSWorkspace launchApplication:]

  4. ,您才能启动包含您的应用程序的应用程序,但前提是您已经是SMLoginItemSetEnabled )

  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()

我想说osascript调用是有效的,因为它的做法与 - [NSWorkspace launchApplication:]大致相同。没有接受束标识符或绝对/相对路径的LS调用将工作。

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.

这篇关于如何在Mac上的沙箱中启动另一个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆