Skip to main content

Hello,

We're updating our OneDrive configurations. I have it covered with placing the new PLIST on systems and quitting OneDrive. But I'd like to be able to relaunch it as the user who's currently logged in. Is there a script or process I could use for this?

Thanks

 

Set a variable for the current logged in user: 

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

 Use that variable to run a launch command as that user:

 

sudo -u $loggedInUser <command>

 

For OneDrive, it should be:

 

sudo -u $loggedInUser /Applications/OneDrive.app/Contents/MacOS/OneDrive