Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have automator running several applescript commands that I want to happen sequentially. For example, I have an empty trash command, then a shut down command. When I run the script, the computer shuts down before the trash empties more than a few files.

How do I make sure that automator completes one task before moving on?

I also have a terminal command for backing up using time machine. I would also like that one to finish before the shut down.

share|improve this question
    
I think empty trash should normally block the script. And if it stops because some file is in use, the workflow should stop because of an error. Can you include the complete script or workflow? You can use tmutil startbackup -b for the backup. –  Lri Jan 10 '13 at 8:01
add comment

1 Answer 1

up vote 1 down vote accepted

Unfortunately empty trash is a message sent to Finder, and, from Automator's point of view, the task finishes when the message is sent.

In this conversation there's a possible solution. You have to modify your Applescript task with a check on the size of the trash:

tell application "Finder"
    set first_size to ""
    set second_size to " "
    set trash_folder to (path to trash folder)

    empty trash

    repeat until first_size is equal to second_size
        set first_size to size of (info for trash_folder) as integer
        delay 2
        set second_size to size of (info for trash_folder) as integer
    end repeat
end tell

This way the task will not end until the size of the trash stops decreasing.

If you use tmutil for time machine backup terminal command, there is a -b option for startbackup command that tells the script to wait until the backup is finished before exiting.

share|improve this answer
add comment

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.