Bump on this. Also interested in something that works like this.
I run a daily policy that checks uptime. If the device reports that it has been up for more than seven days I warn the user with a dismissible CocoaDialog box that their machine has been up for more than seven days. I just run a compare against a hardcoded max days value. End users are given the option to dismiss or restart via a button. The restart button enacts shutdown -r +5 and a CocoaDialog progress bar giving users a five minute countdown.
The warning persists for seven days. When a machine reports fourteen days of uptime, set by another hardcoded variable, during the daily policy run the policy enacts shutdown -r +10 and the same progress bar, this time with no option to dismiss.
I do not bother with a smart group to target the policy, however I do use a smart group to detect machines that have been enrolled for less than two weeks. These machines gets a milder policy that doesn't immediately restart the machine.
Here is a similar post I responded to with a script I use to force a reboot after 4 days while giving the user some deferral options.
https://www.jamf.com/jamf-nation/discussions/27844/jamf-helper-reboot-script-with-deferral
Hi
Any suggestions on how do we prompt user for pre-warning saying "Mac will be restarted in XX minutes of time" prior to actual mac reboot happens?
I use CocoaDialog currently, but given that its latest working version is quite old and the new version is getting close to missing its target release date you could also use Jamf Helper. There are a bunch of tools that may work, depending on your preference. Something along the lines of:
# Cocoa Dialog option
CD="/Applications/cocoadialog.app/Contents/MacOS/cocoadialog"
$CD ok-msgbox --title "Warning" --text "This Mac will be restarted in 5 minutes" --icon "caution" --timeout 300 --float ‑‑button1 "OK"
# JamfHelper option
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
option=" -windowType utility -title Warning -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns" -windowPosition ur"
"$jamfHelper" $option -description "This Mac will be restarted in 5 minutes" -button1 OK -timeout 300
# Jamf displayMessage option
jamf displayMessage -message "This machine will restart in 5 minutes"
# AppleScript option
osascript -e 'display notification "This Mac will be restarted in 5 minutes" with title "Warning" sound name "default"'
Some of these could be combined with the actual trigger to start the restart countdown. The Applescript one tosses up a notification that has a default time out well short of five minutes, but just in case I included it.