Created
March 26, 2012 22:31
-
-
Save acidprime/2210258 to your computer and use it in GitHub Desktop.
Launching an application from the launchd root context as the console user - https://jamfnation.jamfsoftware.com/discussion.html?id=4117
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -x UserName="$(/usr/bin/who | /usr/bin/awk '/console/{print $1;exit}')" | |
echo "Derived Console username: $UserName" | |
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')" | |
echo "Found PID: $LoginWindowPID" | |
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$UserName" /usr/bin/open /Applications/Calculator.app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment