Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: An AppleScript to automate Address Book backups System 10.4
Tiger only hintI was browsing through old hints and the forums the other day and I came across this hint about Address Book and iCal data loss during a sync on 10.4. As usual, the first thing in my mind was, how do you automate backups then? While searching for an answer, I came across this forum post on applescript.net. I took some of the code there and made this AppleScript to perform an automated backup via ApplesSript UI scripting. I found that using the iCal AppleScript appointment reminder is a nice way for those of us who don't like using cron to schedule backups and such.

There are some Apple failsafes built into the code to make sure that UI scripting is enabled. Also, I did make the "move" section hard coded to the ~/Documents/ABBackup/ folder, so make sure that is created prior to running the script. I know that this works on Tiger, but because of the UI scripting, I am not sure if it will work on previous system builds.

NOTE: You do have to have the "Enable access for assistive devices" box checked in the Universal Access preference pane, so that the UI scripting code works.

[robg adds: I tested this, and it works as described (I didn't schedule it via iCal; just ran the script in ScriptEditor). If someone tests this on 10.3, please let me know if it works and I'll take off the 10.4 tag...]
    •    
  • Currently 2.20 / 5
  You rated: 1 / 5 (5 votes cast)
 
[14,176 views]  

10.4: An AppleScript to automate Address Book backups | 9 comments | Create New Account
Click here to return to the '10.4: An AppleScript to automate Address Book backups' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: An AppleScript to automate Address Book backups
Authored by: marook on Dec 01, '05 08:36:51AM

There's a few errors in that script (at least on 10.4.3..) New script available here:
http://www.hjemme.dk/media/BackUpAB.scpt.zip

Best,

---
/Marook



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: kainewynd2 on Dec 01, '05 11:31:16AM

Thanks for tweaking the script - specifically, I always display file extensions so it never occured to me that appending the .abbu extension would cause possible issues with others.



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: marook on Dec 01, '05 04:02:14PM

No problem.. :-)

The second issues was that you where using $USER in the line to make the 'mv' command, and your should have used the UserName AppleScript var defined in the top... How it worked for robg, I'm not able to tell... ;-)

---
/Marook



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: kainewynd2 on Dec 02, '05 05:52:11AM

Hmm, the $USER variable works for me as well... do you have the BSD subsystem installed, by chance? That would be very interesting to know if that is what caused the issue there...



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: legepe on Dec 02, '05 02:25:56AM

hello,
very strange, doesn't work for me with a french OS X 10.4.3 version !
too many applescripts errors !
I did'nt know that the system language had a importance with AppleScripts !
I was very interested



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: kainewynd2 on Dec 02, '05 05:56:34AM

Did you try Marook's edit of the script? He changed a few items that caused problems on his machine, but not on robg's or mine. Perhaps you share a common difference...?

Also, this does use UI scripting, so if the UI commands for the French version need to be in French (or the section that selects the Desktop as the save location needs a different letter instead of "d") then this could also cause your problem.



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: flyingcactus on Dec 02, '05 11:17:32AM

This sems like a long and involded way of backing up the addressbook information - especially when it specifically involvs UI scripting, which may or may not be turned on. This also can't be done in the background, addressbook will actually open to preform the backup. It would seem alot simpler to just copy the folder ~/Library/Application Support/AddressBook to back up the data. It is a much easier script to write and to restore it, all you have to do is replace the folder with your backup copy.



[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: kainewynd2 on Dec 02, '05 01:07:58PM
As flyingcactus pointed out, this is a rather drawn out and involved way of backing up Address Book info. I took his advice and made a MUCH simpler AppleScript that just copies the local AddressBook folder from ~/Library/Application Support and dumps it into a dated directory in your Documents/ABBackup folder (you still need to make that folder by hand, if anyone could throw a folder checking and creation applescript page at me, I would really appreciate it). Below is the code:

do shell script "date +%m-%d-%y" -- Gets the Date
set todaysDate to result 
set folderName to "ABBackup_" & todaysDate -- Sets variable for Making dated folder
do shell script "echo $USER" -- Gets username
set userName to result
do shell script "mkdir /Users/" & userName & "/Documents/ABBackup/" & folderName & "/" -- Makes dated folder, ideal for Daily backups at the moment
do shell script "ditto '/Users/" & userName & "/Library/Application Support/AddressBook/' /Users/" & userName & "/Documents/ABBackup/" & folderName & "/" -- Dittos the Address Book to ~/Documents/ABBackup/datedfolder


[ Reply to This | # ]
10.4: An AppleScript to automate Address Book backups
Authored by: mark hunte on Dec 02, '05 06:30:56PM
do shell script "date +%m-%d-%y" -- Gets the Date
set todaysDate to result
set dated_folder to "ABBackup_" & todaysDate -- Sets variable for Making dated folder
tell application "Finder"
	set backup_Folder to "ABBackup"
	set Sup_path_folder to path to application support from user domain as string
	set addbookFolder to folder "AddressBook" of folder Sup_path_folder as string
	set doc_path_folder to path to documents folder from user domain as string
	if not (exists folder backup_Folder of folder doc_path_folder) then
		make new folder at doc_path_folder with properties {name:backup_Folder}
	end if
	set backup_Folder to folder backup_Folder of folder doc_path_folder as string
	if not (exists folder dated_folder of folder backup_Folder) then
		make new folder at backup_Folder with properties {name:dated_folder}
	end if
	tell application "Finder"
		duplicate items of folder addbookFolder to folder dated_folder of folder backup_Folder with replacing
	end tell
end tell
<p>---<br>mh</code></pre>


[ Reply to This | # ]