10.5: Run a Time Machine backup then shut down

Jun 27, '08 07:30:03AM

Contributed by: llee

Here's an AppleScript I use to run a Time Machine backup, and then shut down the machine. As is the case with most shut down scripts, I suppose it would be a good idea to quit whatever programs you know of that are open before running the script.

property querylist : {"backupd"}
property app_is_up : missing value
set app_is_up to false
do shell script 
"/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-help
er > /dev/null 2>&1  &"

repeat
   delay 10
   repeat with i in querylist
       set the_ps to paragraphs of (do shell script "/bin/ps -acx")
       tid("/")
       repeat with _line in the_ps
           if _line is "" then
           else
               if _line contains i then
                   set app_is_up to true
               end if
           end if
       end repeat
       tid("")
   end repeat
   if app_is_up then
       set app_is_up to false
   else      
       tid("")
       ignoring application responses
           tell application "loginwindow" to «event aevtshut»
       end ignoring
       exit repeat
   end if
end repeat
on tid(s)
   set my text item delimiters to s
end tid
[robg adds: I haven't tested this one, beyond making sure it compiled in Script Editor. After pasting into Script Editor, save it as a script then use your favorite method of making it easier to access -- toolbar, sidebar, dock, or hot keys via a third-party app.]

Comments (5)


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