Documentation and course materiaal provides this script to Display a message to a user, if they click OK, then open Self Service.
messageToDisplay="$4"
policyToExecute="$5"
policyAction="$6"
buttonClicked=$(osascript << EOF
button returned of (display dialog "$messageToDisplay" buttons {"OK", "Cancel"} default button 1)
EOF)
if [[ "$buttonClicked" == "OK" ]];then
open "jamfselfservice://content?entity=policy&id=$5&action=$6"
fi
However, this fails when the script is run in a policy, due to the JSS running the script as root instead of currentUser. Working with Jamf support we were able to make the modification below, which allows the script to run as intended when deployed via policy.
messageToDisplay="$4"
policyToExecute="$5"
policyAction="$6"
currentUser=$(ls -l /dev/console | awk '{ print $3 }')
buttonClicked=$(sudo -u $currentUser /usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to button returned of (display dialog "$messageToDisplay" buttons {"OK", "Cancel"} default button 1)
end tell
END)
if [[ "$buttonClicked" == "OK" ]];then
sudo -u $currentUser open "jamfselfservice://content?entity=policy&id=$5&action=$6"
fi