Hello! I should warn you that I know almost no AppleScript, except what I can cobble together from Google searches, so it’s possible that I’m missing something obvious.
I’m trying to come up with an AppleScript which will warn the logged in user that the system will shut down in 60 seconds unless the user presses “Cancel” within 60 seconds
Here is what I have come up with:
set question to display dialog "Shutting Down in 60 seconds." giving up after 60 with title "System Event" with icon stop buttons {"Shut Down", "Cancel"}
set answer to button returned of question
if answer is equal to "Cancel" then
return
end if
-- if we get here, either they pressed 'Shut Down' or the timer expired
tell application "System Events"
shut down
end tell
Now, the only improvements that I would like to make are:
-
I would like to display the exact time that the shutdown will occur
-
If possible, I would like to be able to shut down without apps being given the chance to interrupt the shutdown. {I realize this is dangerous, but the point of this AppleScript is to be run automatically when the battery is very, very low. Also, I’m the only user of this Mac, so any mishaps will be my own fault.}
-
Are there any other improvements that people who know AppleScript would suggest?
Thanks!