Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

numlock

macrumors 68000
Original poster
Mar 13, 2006
1,590
88
There were a few applescripts available online to backup address book in Tiger that i was able to fit into my backup workflow. Now in Leopard with the backup option moving from the file menu to the export menu which resides in the file menu I havent either seen a new script for address book in Leopard or managed to tweak the Tiger version to make it work.

Does anyone here have any solution?

this is the original script taken from bbs.applescript.net

HTML:
tell application "Address Book" to activate
tell application "System Events"
   tell process "Address Book"
       tell menu bar 1
           click menu item "Back up Address Book…" of menu "File"
       end tell
   end tell
end tell

thanks in advance
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
Here.
Code:
tell application "Address Book" to activate
tell application "System Events"
	click menu item "Address Book Archive…" of menu "Export" of menu item "Export" of menu "File" of menu bar 1 of process "Address Book"
end tell
 

numlock

macrumors 68000
Original poster
Mar 13, 2006
1,590
88
Here.
Code:
tell application "Address Book" to activate
tell application "System Events"
	click menu item "Address Book Archive…" of menu "Export" of menu item "Export" of menu "File" of menu bar 1 of process "Address Book"
end tell

thanks. but i managed to figure it out on my own yesterday with help from prefab´s uibrowser. Even though its a pretty easy script i find it very rewarding to be able to get something like this to work.

One question though. What would you say is the best way to navigate through the the save dialog? I have found that even though i always save the ical and address book backups in the same place sometimes the save location gets moved to the documents folder. So i added a few extra steps where it searches for the specific folder and then selects it and then saves the backup.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
thanks. but i managed to figure it out on my own yesterday with help from prefab´s uibrowser. Even though its a pretty easy script i find it very rewarding to be able to get something like this to work.

One question though. What would you say is the best way to navigate through the the save dialog? I have found that even though i always save the ical and address book backups in the same place sometimes the save location gets moved to the documents folder. So i added a few extra steps where it searches for the specific folder and then selects it and then saves the backup.
I don't know how to do that. GUI scripting is always a *****.
Instead, this script will save a backup to the desktop and then move it to wherever.
Make sure to edit line 17 to point to the location you want to move the backup file to.
Code:
tell application "Address Book" to activate
tell application "System Events"
	tell process "Address Book"
		click menu item "Address Book Archive…" of menu "Export" of menu item "Export" of menu "File" of menu bar 1
		delay 0.5
		keystroke "d" using command down
		keystroke return
	end tell
end tell

-- If your address book is very large you might have to increase this delay.
delay 2

tell application "Finder"
	
	-- Change the destination folder to the location to save the backup.
	set destination_folder to ((path to desktop as string) & "Right Here:") as alias
	
	set desktop_items to name of every item of the desktop
	repeat with i from 1 to number of items in desktop_items
		set this_item to item i of the desktop_items
		if this_item ends with "abbu" then
			set backup_file to ((path to desktop as string) & this_item) as alias
		end if
	end repeat
	move backup_file to destination_folder replacing yes
end tell
 

HWMRHEA3

macrumors newbie
Aug 21, 2008
3
0
Can't make it work

I have tried messing with the script, and was able to modify it, but I cannot make it save to the folder that I want it in. It keeps stopping at the "Right Here:" part. Any ideas? Here is the script as I have it:

tell application "Address Book" to activate
tell application "System Events"
tell process "Address Book"
click menu item "Address Book Archive…" of menu "Export" of menu item "Export" of menu "File" of menu bar 1
delay 0.5
keystroke "d" using command down
keystroke return
tell application "Address Book" to quit
end tell

end tell

-- If your address book is very large you might have to increase this delay.
delay 2

tell application "Finder"

-- Change the destination folder to the location to save the backup.
set destination_folder to (("Macintosh HD:Users:Documents:Oft Used") & "Right Here:") as alias

set desktop_items to name of every item of the desktop
repeat with i from 1 to number of items in desktop_items
set this_item to item i of the desktop_items
if this_item ends with "abbu" then
set backup_file to (("Macintosh HD:Users:Desktop:") & this_item) as alias
end if
end repeat
move backup_file to destination_folder replacing yes
end tell
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
You need to change the line
Code:
set destination_folder to (("Macintosh HD:Users:Documents:Oft Used") & "Right Here:") as alias
... to include your home folder in the path.

Code:
set destination_folder to ("Macintosh HD:Users:[COLOR="Red"][I]your_username[/I][/COLOR]:Documents:Oft Used:Right Here:") as alias
Change the red part to your username.
 

HWMRHEA3

macrumors newbie
Aug 21, 2008
3
0
Thanks, but no joy

I followed your recommendation, but it still has the problem with the "Right here" part of the script.

The error is:

File Macintosh HD:Users:hwr3:Documents:Oft UsedRight Here: wasn’t found.

Any ideas? It's a good script, but for some reason, it makes the backup, but can't finish moving it.

A quick question: is it easy to tell the apple script to copy and paste a filename from the desktop to a certain folder?

I am using Leopard 10.5.4 on an iMac.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
Make this one line script
Code:
choose folder
run the script and navigate to the folder where you want your backups to be saved. When the script is finished running copy and past the result into the appropriate place in the original script.
 

HWMRHEA3

macrumors newbie
Aug 21, 2008
3
0
Thank you for the responses

What I ended up doing to move the file was this:

Code:
tell application "Finder" to activate
tell application "Finder" to move ("Macintosh HD:Users:hwr3:Desktop:Address Book Backup.abbu:") to folder ("Macintosh HD:Users:hwr3:Documents:Oft Used:")

Worked like a charm. So now I have the script do the backup of my Address Book and then move that file to the folder I wanted it in. I then have in the same script to do the same thing for iCal.

The whole script to do both is:
Code:
tell application "Address Book" to activate
tell application "System Events"
	tell process "Address Book"
		click menu item "Address Book Archive…" of menu "Export" of menu item "Export" of menu "File" of menu bar 1
		delay 0.5
		keystroke "Address Book Backup.abbu"
		keystroke "d" using command down
		keystroke return
		tell application "Address Book" to quit
	end tell
end tell

tell application "Finder" to activate
tell application "Finder" to move ("Macintosh HD:Users:hwr3:Desktop:Address Book Backup.abbu:") to folder ("Macintosh HD:Users:hwr3:Documents:Oft Used:")

tell application "iCal" to activate
delay 2
tell application "System Events"
	tell menu item "Export…" of menu "File" of menu bar 1 of application process "iCal" to click
	delay 1
	keystroke "iCal Backup"
	keystroke "d" using command down
	delay 1
	keystroke return
	tell application "iCal" to quit
	
	tell application "Finder" to activate
	tell application "Finder" to move ("Macintosh HD:Users:hwr3:Desktop:iCal Backup.ics:") to folder ("Macintosh HD:Users:hwr3:Documents:Oft Used:")
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.