Selecting any number of addresses from the address book and running this script returns the data I need:
tell application "Address Book"
set thePeople to selection
repeat with aPerson in thePeople
set theID to id of aPerson
tell application "System Events" to open location "addressbook://" & theID
set theName to name of aPerson
set theCompany to organization of aPerson
set theAddresses to addresses of aPerson
repeat with anAddress in theAddresses
set theStreet to street of anAddress as text
set theCity to city of anAddress as text
set theState to state of anAddress as text
set theZip to zip of anAddress as text
end repeat
-- this dialog shows me what I've collected
display dialog (theName & "
" & theCompany & "
" & theStreet & "
" & theCity & ", " & theState & " " & theZip)
end repeat
end tell
However, I need to count the address records I’ve selected, and display that incrementally as well. I’m hoping to get:
Selected Address 1
Name
Company
Address
City, St Zip
Selected Address 2
Name
Company
Address
City, St Zip
etc. Trying dozens of flavors of “repeat with i to count of x” does not seem to work.
tell application "Address Book"
set thePeople to selection
set i to (the count of thePeople)
repeat with aPerson in thePeople
set theID to id of aPerson
tell application "System Events" to open location "addressbook://" & theID
set theName to name of aPerson
set theCompany to organization of aPerson
set theAddresses to addresses of aPerson
repeat with anAddress in theAddresses
set theStreet to street of anAddress as text
set theCity to city of anAddress as text
set theState to state of anAddress as text
set theZip to zip of anAddress as text
end repeat
-- this dialog shows me what I've collected - but should show the number of the record that's being processed: 1, 2, 3 etc.
display dialog ("Record Number " & (item i of the (count of thePeople)) & "
" & theName & "
" & theCompany & "
" & theStreet & "
" & theCity & ", " & theState & " " & theZip)
end repeat
end tell
I’ve found several “repeat with i to count of X” posts and examples, but can’t figure out to integrate any of them here. Any assistance is appreciated.
Model: pb tibook 667
AppleScript: 1.9.3
Browser: Safari 312.3.1
Operating System: Mac OS X (10.4)