Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using the following Applescript to run a Time Machine backup, and then shut down OS X on the computer at our store.

do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper"

repeat
    delay 10
    if not IsProcRunning("backupd-helper") then
        ignoring application responses
            tell application "loginwindow" to «event aevtshut»
        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

It works fine and shuts down the computer unless another user is logged in, then the Security Agent window pops up asking for an administrator username and password.

I'm curious if someone can help me add to this script the ability to check if the Security Agent window is open, and if it is, to enter the username and password in their relative fields?

share|improve this question

1 Answer 1

If you can go to sleep instead of shutting down, it wouldn't require administrator privileges or confirmation from other logged in users:

do shell script "tmutil startbackup -b"
tell application "System Events" to sleep

You could also use shutdown (it ejects disks properly and so on, but you could lose some unsaved changes):

do shell script "tmutil startbackup -b && shutdown -h now" with administrator privileges

A shell function that could be added to ~/.profile or ~/.bash_profile:

tmshut() { sudo -s -- 'tmutil startbackup -b && shutdown -h now'; }
share|improve this answer
    
I appreciate the answer, but I'm a little confused on how to implement it. First off, are you suggesting that I just put the computer to sleep instead of shutting it down? If I use your second idea, of using shutdown, how would I work that into my existing code? Or would I just replace my code with yours? –  stefmikhail Oct 15 '11 at 21:32
    
I edited the answer. tmutil -b basically replaces the code posted in the question. (tmutil = Time Machine utility, added in 10.7; -b = block, or wait until the backup has finished.) –  ؘؘؘؘ Oct 16 '11 at 9:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.