Execute macOS scripts as Defined User
Description
By default, the FileWave Client executes scripts and tasks with elevated permissions (root on macOS). ThisThe additionbelow shows a method to the start oflaunch a script will execute itcommand as thean currently logged-inalternate user (alsowhen knownran asthrough the console user).FileWave.
Ingredients
- Text editor
- FileWave Central
Directions
The
The beforebelow method not only shows a method to define the desireduser, actions.but
#!/bin/zshgrabs current_user=$(statthe -f%Sucurrent /dev/console)'console' current_user_id=$(iduser. -u $current_user)#!/bin/zsh
current_user=$(stat -f%Su /dev/console)
current_user_id=$(id -u $current_user)
whoami
launchctl asuser $current_user_id sudo -u $current_user whoami
echo "hello world" >> /Users/$current_user/Desktop/test.txt
When
ran through FileWave, the output of the above will show the output of the 'whoami' command has altered, by first echoing the root username and then the name of the active console user of the device.If the current user logged in where 'sholden', the output should show:
root
sholden