Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created March 26, 2012 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidprime/2210258 to your computer and use it in GitHub Desktop.
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
#!/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