One thing you have to remember when writing scripts for Jamf is that Jamf executes everything as root, not the currently logged in user. Because of this, your current script has two issues:
1) The check for the current user is going to always return root if run directly. Instead you can use this bash oneliner to get the currently logged on user.
CURRENT_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name
&& ! /loginwindow/ {print$3}')
Then you can check if the user is the admin user as normal.
if [[ "$CURRENT_USER" = "admin" ]]; then
...do something here
fi
2) Since the context for the script is root, when you attempt to open a UI element for the user, you will need to use sudo -u $CURRENT_USER to instead run your command to open then UI element in the user context.
sudo -u "$CURRENT_USER" -- osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "tail -f /var/log/jamf.log"'
All together this would be
#!/bin/bash
CURRENT_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name
&& ! /loginwindow/ {print$3}')
if [[ "$CURRENT_USER" = "admin" ]]; then
sudo -u "$CURRENT_USER" -- osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "tail -f /var/log/jamf.log"'
fi
One thing you have to remember when writing scripts for Jamf is that Jamf executes everything as root, not the currently logged in user. Because of this, your current script has two issues:
1) The check for the current user is going to always return root if run directly. Instead you can use this bash oneliner to get the currently logged on user.
CURRENT_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name
&& ! /loginwindow/ {print$3}')
Then you can check if the user is the admin user as normal.
if [[ "$CURRENT_USER" = "admin" ]]; then
...do something here
fi
2) Since the context for the script is root, when you attempt to open a UI element for the user, you will need to use sudo -u $CURRENT_USER to instead run your command to open then UI element in the user context.
sudo -u "$CURRENT_USER" -- osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "tail -f /var/log/jamf.log"'
All together this would be
#!/bin/bash
CURRENT_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name
&& ! /loginwindow/ {print$3}')
if [[ "$CURRENT_USER" = "admin" ]]; then
sudo -u "$CURRENT_USER" -- osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "tail -f /var/log/jamf.log"'
fi
cool thanks let me try that.