xcrun from a sandboxed macOS app

Is it possible to run xcrun from a sandboxed macOS app?

The following code doesn't work and raises the error message in the console.

Code Block
let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/xcrun")
try! task.run()

Code Block
xcrun: error: cannot be used within an App Sandbox.


Are there any workarounds for this? I don't think it is possible to get read permission's for the /usr/bin directory from the user. Or should I be creating a bug report and trying to work through a temporary exception?
xcrun contains an explicitly check for it being run from within a sandbox. There’s no way to bypass this.

What do you plan to run using xcrun?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I was hoping to build a small utility app that let's you send push notifications to the simulator for testing/debugging via xcrun simctl push.
On a related note, is it possible to run the same command from XCTest where the target application is iOS? The goal here is to send a push notification to the simulator during UI Testing. Process doesn't exist on iOS (only macOS) so it won't work out of the box.

I was hoping to build a small utility app that let's you send push notifications to the simulator …

… and distributing it via the Mac App Store?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

… and distributing it via the Mac App Store?

That was the plan, yes. Is that violating some review guideline I’m not aware of? I’ve only done iOS apps before not macOS so I’m not confident I know all of them yet.

That was the plan, yes. Is that violating some review guideline I’m not aware of? I’ve only done iOS apps before not macOS so I’m not confident I know all of them yet. 

So how would you do this on iOS?

That's the trick about the sandbox. If you can't do it on iOS, then you probably won't be able to do it in the sandbox, at least not without jumping through some hoops. Apple does provide many hoops for you and your users' exercise needs. In this case, you will want to use NSUserScriptTask. You will have to tell the users how to construct a script to call this function, or make one available for download on your website. Then, the user will have to copy the script into NSApplicationScriptsDirectory. You can open that folder in the Finder for them. Then, you can help them select the proper script for a given operation.

The only thing you have to be careful with regarding App Review is that your app has to work properly and provide meaningful features without this. App Review will not turn on any of these extras, at least not at first.

So how would you do this on iOS?

Sorry, I was mentioning I am only familiar with the iOS App Store guidelines, not the Mac App Store ones. This definitely isn't possible on iOS 😀

It sounds like this most likely isn't possible inside the sandbox. I'll table this idea or release something small outside of the App Store (and without sandboxing). Thanks for the help there.



Going back to the original question, is it possible to execute a command from XCTest where the target application is iOS? This works when macOS is the host target via Process(), but that doesn't exist on iOS so XCTest can't reference it.

Sorry, I was mentioning I am only familiar with the iOS App Store guidelines, not the Mac App Store ones. This definitely isn't possible on iOS

It's not a question of guidelines, but the architecture of the sandbox.

It sounds like this most likely isn't possible inside the sandbox.

Not unless you use the step-by-step instructions I posted above.

is it possible to execute a command from XCTest where the target application is iOS? 

Yes

is it possible to execute a command from XCTest where the target application is iOS?  Yes

That's great! Can you shed some light on how it is done? I tried via Process() but, as I mentioned, that work with iOS.
xcrun from a sandboxed macOS app
 
 
Q