Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JackMaurer

macrumors member
Original poster
Dec 22, 2008
72
0
Hi Guys,

I did a quick search on this but couldn't get much of an answer.

I'm looking at exporting one of my groups from Address Book to a numbers worksheet - Is there a simple way to do this?

I tried right clicking on the group but that only seems to export the group as a vCard rather then into a spreadsheet format

Any help would be appreciated

Thanks
 
AppleScript might do the trick. Address Book is a little tricky, so if it doesn't work, let me know and it should be fixable. My AB database is pretty paltry, so if you're using it a lot, you might have something more complex than what I've scripted for.

(Also, this only fetches names, phone numbers, email address and snail mail addresses. If you want more, it should be easily fixed.)

Code:
on returnString(firstList, secondlist)
	set tempString to ""
	set counter to number of items of firstList
	repeat with x from 1 to 3
		if x > counter then
			set tempString to tempString & "N/A" & tab & "N/A" & tab
		else
			set tempString to tempString & (item x of firstList) & tab & (item x of secondlist) & tab
		end if
	end repeat
	return tempString
end returnString

on collapseString(multiGrafString)
	set tempString to (paragraphs of multiGrafString) as text item
	set TID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to tab
	set tempString to tempString as text
	set AppleScript's text item delimiters to TID
	return tempString
end collapseString

tell application "Address Book"
	set groupName to text returned of (display dialog "Please enter the name of the group you wish to export:" default answer "" buttons {"Cancel", "OK"} default button 2)
	set totalRecs to number of people
	set output to "Name" & tab & "Phone Label 1" & tab & "Phone 1" & tab & ¬
		"Phone Label 2" & tab & "Phone 2" & tab & "Phone Label 3" & ¬
		tab & "Phone 3" & tab & "Email Label 1" & tab & "Email 1" & tab & ¬
		"Email Label 2" & tab & "Email 2" & tab & "Email Label 3" & tab & ¬
		"Email 3" & tab & "Address Line 1" & tab & "Address Line 2" & tab & ¬
		"Address Line 3" & return
	repeat with x from 1 to totalRecs
		set theGroup to (name of group of person x)
		if groupName is in theGroup then
			set theName to name of person x
			set thePhoneNumbers to the value of phone of person x
			set thePhoneLabels to the label of phone of person x
			set theEmail to the value of email of person x
			set theEmailLabels to the label of email of person x
			set theAddress to the formatted address of address of person x
			set thePhoneString to my returnString(thePhoneLabels, thePhoneNumbers)
			set theEmailString to my returnString(theEmailLabels, theEmail)
			set theAddressString to my collapseString((theAddress as string))
			set output to output & theName & tab & thePhoneString ¬
				& theEmailString & theAddressString & return
		end if
	end repeat
end tell

activate me

set theDefaultName to groupName & " output.txt"

set docAlias to path to documents folder
set newFileName to (choose file name with prompt "Please enter a file name" default name theDefaultName default location docAlias)
set newFileNameString to newFileName as string
try
	set outPutfile to open for access file newFileNameString with write permission
on error errNum number errMsg
	display dialog ("Error: " & errNum as string) & return & errMsg
end try
try
	write output to outPutfile starting at eof
on error errNum number errMsg
	display dialog ("Error: " & errNum as string) & return & errMsg
end try
try
	close access outPutfile
on error errNum number errMsg
	display dialog ("Error: " & errNum as string) & return & errMsg
end try

There should be no trouble opening the resulting file in Numbers.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.