An AppleScript to generate a timed shutdown

Feb 17, '04 10:09:00AM

Contributed by: StevenT

I searched on a lot of Apple sites to find an easy shutdown script. shutdown -h -t xx works fine in the Terminal, but it's too clumsy. So I managed to make a (very) little AppleScript (my first one, BTW) which works.


(* how many seconds before we remove the notice? *)
property dialog_timeout : 3

repeat
  try
    display dialog "In how many minutes must the computer be shutdown?" ¬
    default answer ""
    set the time_amount to the text returned of the result as integer
    if the time_amount is greater than 0 then exit repeat
    on error number error_number
    if the error_number is -128 then return "user cancelled"
  end try
end repeat

if the time_amount is 1 then
  set the my_minuten to "minute"
else
  set the my_minuten to "minutes"
end if

display dialog "The computer will be shutdown in " & time_amount & " " & ¬
my_minuten & "!" buttons {"Ok"} default button 1 giving up after dialog_timeout

delay time_amount * 60
tell application "Finder" to shut down
There is no canceling as I know, that would a nice addition...

[robg adds: 10.3 includes a scheduled shutdown in the Energy Saver prefs, though it might be easier to run this script as opposed to accessing the prefs each time...]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040209142949995