Restart message

Asifahmed
New Contributor III

I am restarting the mac via a policy, I used shutdown command to restart, User are getting popup to select restart operation now, after 1 min, after 5 mins, after 1 Hrs or after 2 Hrs. If user select 1 Hr or 2 Hrs then before going to be restarted user should get a popup window that mac is going to be restarted in some mins/time. So that user can be ready to save all opened item. May I know which command will help me or any flag is there for shutdown command? Warn-ing command is showing message in terminal but no popup window, any idea for this?

9 REPLIES 9

mark_mahabir
Valued Contributor

You can use the "osascript" command to display a dialog box with a message to the user before the shutdown/restart process starts. Here's an example of how you can use it:

 

osascript -e 'tell app "System Events" to display dialog "Your Mac will restart in 10 minutes. Please save your work and close all applications." buttons {"OK"} default button 1 with icon caution'

 

This will display a dialog box with a message "Your Mac will restart in 10 minutes. Please save your work and close all applications." and an OK button. You can customize the message and the time as per your requirement.

Once the dialog box is displayed, you can use the "shutdown" command to initiate the restart process. Here's an example of how you can use it:

 

shutdown -r +10

 

 

This will restart the Mac in 10 minutes after the command is executed. You can change the time as per your requirement.

Note: The "osascript" command will display the dialog box on the user's screen, so the user must be logged in for this to work.

Jamf helper and shutdown command has been used to choose the time to restart. If a user choose 1 hr later to restart then how logged in user will get the message 5 mins back that in 5 min mac will take restart? In osascript do it have option to schedule task like shutdown do?

The "osascript" command itself doesn't have an option to schedule tasks like the "shutdown" command. However, you can use a combination of "osascript" and the "at" command to schedule the message to be displayed at a specific time.

For example, if the user chooses to restart the Mac in 1 hour, you can use the following commands to schedule a message to be displayed 5 minutes before the restart:

 

echo 'osascript -e "tell app \"System Events\" to display dialog \"Your Mac will restart in 5 minutes. Please save your work and close all applications.\" buttons {\"OK\"} default button 1 with icon caution"' | at now + 55 minutes

 

This command schedules the "osascript" command to be executed in 55 minutes (1 hour - 5 minutes) from now. When the command is executed, it will display a dialog box with the message "Your Mac will restart in 5 minutes. Please save your work and close all applications."

After the message is displayed, you can use the "shutdown" command to restart the Mac after 5 minutes:

 

shutdown -r +5

 

This command will restart the Mac in 5 minutes after the command is executed.

Note: The "at" command schedules a task to be executed at a specific time, so make sure that the Mac's system clock is accurate before using this command. Also, the "osascript" command will display the dialog box on the user's screen, so the user must be logged in for this to work.

At is disabled by default. To enable it another restart is needed. Looking for an option in shutdown command. 

sgiesbrecht
Contributor III

Why are you using a script, why don't you use the Policy > Restart Options payload?

You can use User Interaction for the messages

I used Jamfhelper and script to reschedule as per user's wish. In your way user cant reschedule with multiple time stamp. In my script user can restart it just now, after 1 min, after 5 mins, after 1 Hr and after 2 Hrs. In your way it is not possible I think, please let me know if I am wrong here.

RobinJJ
New Contributor III

Checkout swiftDialog https://github.com/bartreardon/swiftDialog 

 

The --blurscreen is legandary

Asifahmed
New Contributor III

I just want to give a popup before 5 mins of restart operation. I am not understanding how I will calculate the restart time and set a timestamp before 5 mins of restart operation so that popup will come up before restart to save all opened docs.

RobinJJ
New Contributor III

Prioritize script to run before action, add "sleep 300"  script before action, then run restart. Should work