I have a feeling i may be over thinking this, but i can't seem to do what i want. I basically want a nice and friendly way to ask the user to restart after a policy that requires a restart runs. I really don't care for the way JAMF implements restarts, so i'm using a cocoaDialog msgbox to run after the policy runs with the option to restart now or later. I could program the restart button to just 'shutdown -r now', but i'd rather do a friendlier restart like "osascript -e 'tell app "System Events" to restart'". The latter works fine when run from Self Service, but when run from the "Recurring check in" trigger, it fails with an error "28:35: execution error: An error of type -10810 has occurred. (-10810)" which i believe is related to running as the root user, but then why does it work from Self Service?
Any suggestions would be greatly appreciated. Here's the code i'm using:
#!/bin/bash
CD="/opt/local/CocoaDialog.app/Contents/MacOS/CocoaDialog"
rv=`$CD msgbox --title "Restart Computer Please" --text "$4 has been installed and requires a restart"
--informative-text "Click Restart to restart now. Click Later to restart at a later time."
--no-newline --button1 "Restart" --button2 "Later" --float`
if [ "$rv" == "1" ]; then
echo "User selected Restart"
osascript -e 'tell app "System Events" to restart'
elif [ "$rv" == "2" ]; then
echo "User selected Later"
exit
fi