Applescript Import Into Address Book - A Better Way?

Discussion in 'Mac Programming' started by Bonusgrabber, Jul 15, 2012.

  1. macrumors newbie

    May 10, 2012
    I have written an applescript that uses the export from Filemaker to import into Address Book.

    The script adds a header file to the exported file first. (Not a problem there)

    The script then calls Address Book and does a click menu item to open the Import dialog (Not a problem there)

    Selecting the folder and filename works but I am sure there is a better way to do it. Here is the code:

    set importpath to "/Users/TWK/Documents/Import/"
    set headerfilepath to "/Users/TWK/Documents/System/"
    set AddressBookImportFileName to "AddressBookImportNew2.csv"
    -- Run cat in shell to add headers to import file
    do shell script "/bin/cat '" & headerfilepath & "Headers For Filemaker Export From Address Book.txt' '" & importpath & "Filemaker Export From Address Book.csv' >'" & importpath & AddressBookImportFileName & "'"
    tell application "Address Book" to activate
    tell application "System Events"
    	tell application process "Address Book"
    		-- Open Import File Dialog in Address Book
    		click menu item "Import…" of menu 1 of menu bar item "File" of menu bar 1
    		-- Open Goto Folder Dialog and Enter Import Path
    		-- Is there a better way to do this?
    		keystroke "g" using {shift down, command down}
    		keystroke importpath
    		delay 1
    		keystroke return
    		delay 3
    		-- Type In Import Filename to Select it
    		-- Is there a better way to do this?
    		keystroke AddressBookImportFileName
    		delay 3
    		keystroke return
    		delay 1
    		keystroke return
    	end tell
    end tell

Share This Page