Address book backup

Discussion in 'Mac Programming' started by numlock, Jan 28, 2008.

  1. macrumors 65816

    Joined:
    Mar 13, 2006
    #1
    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
     
  2. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #2
    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
     
  3. thread starter macrumors 65816

    Joined:
    Mar 13, 2006
    #3
    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.
     
  4. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #4
    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
     
  5. macrumors newbie

    Joined:
    Aug 21, 2008
    #5
    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
     
  6. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #6
    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.
     
  7. macrumors newbie

    Joined:
    Aug 21, 2008
    #7
    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.
     
  8. macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #8
    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.
     
  9. macrumors newbie

    Joined:
    Aug 21, 2008
    #9
    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
     

Share This Page