Wednesday, December 2, 2009

TimeMachine Backup Then Sleep or ShutDown

With some Googling and piecing together some found scripts, I have put together these two scripts - Apps which I use very often.
  1. TimeMachine_Backup_Then_Sleep.scpt   >>   TimeMachine_Backup_Then_Sleep.app
  2. TimeMachine_Backup_Then_ShutDown.scpt   >>   TimeMachine_Backup_Then_ShutDown.app
You can save scripts as apps to be run at-will. I have no schedules, no crons, no calendar triggers.
When and only when I want to I do a TimeMachine Backup I run one of these programs at the end of the day and I head for bed. It's so nice!
I use QuickSilver, so it's a couple of keystrokes and it's running. I then dim my screen until it's black.
I like to leave the keyboard partially lit so I know if the laptop is indeed on or not.

The scripts source:
  1. do shell script "/bin/bash -c '/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1  &'"
    repeat
        delay 5
        if not IsProcRunning("backupd") then
            ignoring application responses
                tell application "Finder" to sleep
            end ignoring
            exit repeat
        end if
    end repeat
    on IsProcRunning(theProc)
        try
            do shell script "ps auxc | grep \"" & theProc & "\""
            return true
        on error
            return false
        end try
    end IsProcRunning

  2. do shell script "/bin/bash -c '/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1  &'"
    repeat
        delay 5
        if not IsProcRunning("backupd") then
            ignoring application responses
                tell application "Finder" to shut down
            end ignoring
            exit repeat
        end if
    end repeat
    on IsProcRunning(theProc)
        try
            do shell script "ps auxc | grep \"" & theProc & "\""
            return true
        on error
            return false
        end try
    end IsProcRunning

An open "Thank You!" to all you Apple-Scripters out there who have posted code to contribute to my learning. I return the favor by posting my source code for open use.

And that's a wrap!