Fine-Tuning with AppleScript
If you have followed these instructions carefully, you may have noticed one minor problem: When the backup is complete, Fetch is still running.
Now, this isn’t a big deal. You can always manually quit Fetch when it’s finished. If you have the backup scheduled a while before an automatic shutdown of your computer, Fetch will quit automatically—as long as it isn’t in the middle of a transfer. But there’s another way to automate this process, using Fetch and iCal—a way that will also quit Fetch when the backup job is done. It uses AppleScript, which is part of Mac OS X. Follow these steps:
- Open the Script Editor application in the AppleScript folder.
- In the new document window that appears, enter the following code (see
tell application "Fetch" activate mirror alias "HardDiskName:Users:YourName:SourceFolderName:" to url "ftp://UserName:@ftp.YourDomain.com/DestinationFolderName/" format Binary without delete strays quit end tell
Of course, replace all the italicized text in the code with the appropriate information for your source and destination locations.
Figure 12 Script Editor with a simple Fetch-based backup script.
- Choose File > Save.
- In the Save As dialog that appears next (see Figure 13), enter a name for
the script and choose a disk location in which to save it. Choose a file format
of Application, and make sure that none of the checkboxes are turned on. Then
click Save. Note that if you made an error in the script, the script won’t
compile and you won’t be able to save it.
Figure 13 Use this dialog to save the script as an application.
- Choose Script Editor > Quit Script Editor or press Command+Q to quit the Script Editor application.
- Now go back and follow the steps in the earlier section "Automate Your Backup with iCal" to open the script you just created instead of the Fetch document. In fact, you won’t need the Fetch document at all if you have already run the Fetch mirror document once and saved your password to your keychain.
If it takes a long time for the backup to complete—perhaps many files in the source folder have changed, or you have a slow connection to the Internet—you may get an AppleScript timeout error. If that’s the case, modify the script to add two lines, as follows:
tell application "Fetch" with timeout of 300 seconds activate mirror alias "HardDiskName:Users:YourName:SourceFolderName:" to url "ftp://UserName:@ftp.YourDomain.com/DestinationFolderName/" format Binary without delete strays quit end timeout end tell
You can make the number of seconds as long as you think Fetch will need to complete the backup.