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