2

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.

1
  • 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
    Commented Jan 10, 2013 at 8:01

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .