Posted on 03-27-2018 04:55 PM
Hello again!
I'm trying to install our company's app to the Xcode iOS simulator via a script that essentially just runs xcrun simctl install booted [Path and App]
however, as I'm finding out Jamf runs every command/script as sudo which is breaking this command. If I run sudo xcrun simctl install booted [Path and App]
just in the command line I'm told No devices are booted.
but the simulator is booted and I'm staring right at it.
I can always create a new package by installing Xcode then our app to the simulator, however that package ends up being over 6GB and at the end of the day not efficient. So we want to install the new version of the app in the existing simulator.
Is there a way to tell Jamf not to run the command with sudo
?
Here's what I've tried so far:
- Write a script that just runs xcrun simctl install booted [Path and App]
- this works in the command line but fails when pushed out via policy.
- Write a non-compiled AppleScript that runs xcrun simctl install booted [Path and App]
- Script Editor runs the script and it works, fails with the No devices are booted.
error via policy.
- Created a policy with the Files and Processes payload with xcrun simctl install booted [Path and App]
as the Execute Command but again, it runs as root and I get No devices are booted.
.
Thanks for any help!
Solved! Go to Solution.
Posted on 03-27-2018 07:53 PM
Try
#!/bin/bash
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u $loggedInUser)
/bin/launchctl asuser $loggedInUID sudo -iu $loggedInUser /usr/bin/xcrun simctl install booted [Path and App]
Posted on 03-27-2018 05:30 PM
The issue may be that the script is being as root.
What you can do is get the username of the logged in user currentuser=ls -l /dev/console | cut -d " " -f4
then run your command with
su - "${currentuser}" -c xcrun simctl install booted [Path and App]
That might work? I'm not in front of my mac at the moment so I can't test it
Posted on 03-27-2018 05:44 PM
Thanks for the help @curullij. I get an error of Script result: su: unknown login:
Here's the command su - "${currentLoggedInUser}" -c xcrun simctl install booted [Path and App]
Posted on 03-27-2018 07:13 PM
Try this if the script is run via JAMF
su $3 -c xcrun simctl install booted [Path and App]
Posted on 03-27-2018 07:53 PM
Try
#!/bin/bash
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u $loggedInUser)
/bin/launchctl asuser $loggedInUID sudo -iu $loggedInUser /usr/bin/xcrun simctl install booted [Path and App]
Posted on 03-29-2018 03:40 PM
Thanks @mm2270, that totally worked!
Also, thank you everyone for your input and helping come to the solution!