11

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

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

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?

noridon
  • 111
  • 1
  • 4
  • If specifying it by name (or maybe bundle ID) instead of FSRef is acceptable, try that: http://stackoverflow.com/a/7311283/30461 – Peter Hosey Sep 26 '12 at 18:31
  • Thanks. But it couldn't launch neither even if using launchApplication function with application name instead. Probably, the target application may needs to have a launched experience by user at least once previously for launching normally on OS X Lion and Mountain Lion. – noridon Sep 28 '12 at 07:44

2 Answers2

17

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.

ipmcc
  • 29,581
  • 5
  • 84
  • 147
rudy
  • 1,702
  • 11
  • 14
  • 1
    Thanks! Succeeded to launch from XPC Services! – noridon Dec 28 '12 at 02:17
  • that should work as long as you're not intending to submit to the MacAppStore and aren't sandboxing the XPC Service. If you are submitting to the app store they're going to force you to sandbox the XPC Service. – rudy Dec 29 '12 at 00:41
0

Use osascript

osascript -e 'tell application "foo" to open'
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144