Automatically backup Address Book once a day

After a couple of time consuming snafus with Address Book (one involving the "lovely" 10.5.3. update that allowed Mac to sync Address Book with Gmail contacts..grrrr...) I decided to get serious about backing up my address book so I wrote the following applescript for Hazel to run:
I should note that one downfall of this script is that it requires Address Book to actually open, which can be a little surprising the first couple of times it runs.
This script makes an address book archive with the following name format: AddressBookArchive-2008-06-21, where the last bit is the date. It seems to save to the Desktop and, despite my efforts to fix this (see the commented out "do shell script" line), I can't fix it.
Using Hazel, I set up the following rules:
On Applications: if date last matched is not in the last 1 day and Name is Address Book, run AppleScript named MakeAddressBookArchive.scpt
On Desktop: if name starts with AddressBookArchive- and kind is Address Book Archive File, move file to folder AddressBookBackup
For my ~200 contacts, these files are about ~4MB, so they can easily add up. I am considering adding a rule to delete old files from the AddressBookBackup file. My concern is that I won't notice an address is missing until a while later.
Ideally, I would prefer to export everything as a multiple VCard file since this is an open format. Getting the applescript program to "select all addresses" is a little tricky. I can't get the UI scripting to work properly. Booo...
EDIT: this script was adapted from the following link http://www.macosxhints.com/dlfiles/auto_ab_backup_scpt.txt. I removed some the the UI checking since I have it enabled for other reasons. You DO need to enable access for assistive devices.
- Code: Select all
on hazelProcessFile(infile)
do shell script "date +%Y-%m-%d"
set todaysDate to result
set fileName to "AddressBookArchive-" & todaysDate --& ".abbu" AB will auto-add the ending, if you have default Hide Endigs enabled in Finder!
--do shell script "echo $USER"
--set userName to result
tell application "Address Book" to activate
tell application "System Events"
tell process "Address Book"
click menu item "Address Book Archiveā¦" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
delay 1
keystroke fileName
keystroke "d" using command down -- Select Desktop
keystroke return
delay 5 -- Allow AB to save the backup
end tell
end tell
--do shell script "mv -f /Users/" & userName & "/Desktop/" & fileName & " /Users/_myname_/Backup/."
tell application "Address Book"
quit
end tell
end hazelProcessFile
I should note that one downfall of this script is that it requires Address Book to actually open, which can be a little surprising the first couple of times it runs.
This script makes an address book archive with the following name format: AddressBookArchive-2008-06-21, where the last bit is the date. It seems to save to the Desktop and, despite my efforts to fix this (see the commented out "do shell script" line), I can't fix it.
Using Hazel, I set up the following rules:
On Applications: if date last matched is not in the last 1 day and Name is Address Book, run AppleScript named MakeAddressBookArchive.scpt
On Desktop: if name starts with AddressBookArchive- and kind is Address Book Archive File, move file to folder AddressBookBackup
For my ~200 contacts, these files are about ~4MB, so they can easily add up. I am considering adding a rule to delete old files from the AddressBookBackup file. My concern is that I won't notice an address is missing until a while later.
Ideally, I would prefer to export everything as a multiple VCard file since this is an open format. Getting the applescript program to "select all addresses" is a little tricky. I can't get the UI scripting to work properly. Booo...
EDIT: this script was adapted from the following link http://www.macosxhints.com/dlfiles/auto_ab_backup_scpt.txt. I removed some the the UI checking since I have it enabled for other reasons. You DO need to enable access for assistive devices.