I Have this script below, that I’m planning on running on a number of mac’s using Cronnix
It’s fine as it is but I would like to “Sex” it up a bit.
tell application "Terminal"
do script with command "shutdown -h +5.0 - *** This Mac Will SHUT DOWN in 5 minutes ***"
end tell
tell application "Finder"
activate
say "Alert"
display dialog "This Mac Will Shutdown In 5 Minutes" with icon 2
end tell
Were the dialog box displays the message “This Mac Will Shutdown In 5 Minutes” I would like it to count down to zero.
You don’t have to tell the terminal to do that – use do shell script. warned will be whatever you put after the dash.
set warned to do shell script "shutdown -h +5.0 - *** This Mac Will SHUT DOWN in 5 minutes ***"
repeat 4 times
display dialog warned giving up after 60 buttons {"Understood"} default button 1 with icon 0
do shell script "sleep 60" -- less cpu intensive than delay
end repeat
In this Deluxe-solution the actual shutdown is interceptable; it requires Extra Suites (a scripting addition) however.
Countdown only proceeeds with no user input for more than a second.
This allows for comfortable mousing around; e.g. when cancelling the dialog in the last second, countdown temporarily stops.
if CountDownBar(60 * 1, "Machine will shutdown", true) then do shell script "shutdown" -- immediate shutdown shell script
on CountDownBar(maxx, mez, detectMouseMove)
tell application "Finder" to set deskrect to bounds of window of desktop
if item 3 of deskrect > 2500 then set item 3 of deskrect to 1900
set i to 0
set alert volume of (get volume settings) to 90
tell application "Extra Suites"
set mLoc to ES mouse location
set mlocOrig to mLoc
set isCancelled to false
--beep 2
ES move mouse {round ((deskrect's item 3) / 2 + 110), 160}
ES display progress counting to maxx top 120 with caption (mez & " in " & maxx - i & ¬
" secs." & return & return & " MOVE MOUSE TO CANCEL ")
repeat until i = maxx
tell me to do shell script "sleep 1"
try
set rusttijd to round (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'")
if rusttijd > 1 then
set i to i + 1
set isCancelled to ES advance progress by 1 updating caption to (mez & " in " & maxx - i & ¬
" secs." & return & return & " MOVE MOUSE TO CANCEL ")
end if
set mLoc to ES mouse location
if not isCancelled then set kd to ES keys down
if not isCancelled then set isCancelled to kd contains "command" and kd contains "."
if isCancelled = true then
ES close progress
ES move mouse mlocOrig
return false
end if
on error
ES close progress
if not isCancelled then set kd to ES keys down
if not isCancelled then set isCancelled to kd contains "command" and kd contains "."
if isCancelled = true then
ES close progress
ES move mouse mlocOrig
return false
end if
try
if isCancelled = true then ES advance progress by 1 updating caption to "Intercepted !"
end try
return false
end try
end repeat
ES move mouse mlocOrig
do shell script "sleep 0.2"
try
close message window mw1
end try
-- ES advance progress by 1 updating caption to "Resetting."
ES close progress
end tell
return true
end CountDownBar