Posted on 03-08-2023 09:44 AM
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?
03-08-2023 11:49 AM - edited 03-08-2023 11:50 AM
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
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.
Posted on 03-08-2023 11:55 AM
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?
03-08-2023 11:58 AM - edited 03-08-2023 11:59 AM
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.
Posted on 03-08-2023 12:04 PM
At is disabled by default. To enable it another restart is needed. Looking for an option in shutdown command.
Posted on 03-09-2023 01:09 PM
Why are you using a script, why don't you use the Policy > Restart Options payload?
You can use User Interaction for the messages
Posted on 03-10-2023 12:59 AM
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.
Posted on 03-14-2023 07:49 AM
Posted on 03-15-2023 05:29 AM
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.
Posted on 03-15-2023 06:15 AM
Prioritize script to run before action, add "sleep 300" script before action, then run restart. Should work