applescript for address book
MacBook Pro, Mac OS X (10.5.8)
Want to highlight a helpful answer? Upvote!
Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >
Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >
MacBook Pro, Mac OS X (10.5.8)
tell application "Address Book"
set theContacts to the selection
set theText to ""
repeat with thisPerson in theContacts
set theText to theText & name of thisPerson & return
try
set theText to theText & formatted address of first address of thisPerson & return
end try
set theText to theText & return
end repeat
end tell
tell application "TextEdit"
set theNewDoc to make new document
set text of theNewDoc to theText
print theNewDoc
end tell
tell application "Address Book"
set theContacts to the selection
set theText to ""
repeat with thisPerson in theContacts
set theText to theText & name of thisPerson & return
try
set theText to theText & formatted address of first address of thisPerson & return
end try
set theText to theText & return
end repeat
end tell
tell application "TextEdit"
set theNewDoc to make new document
set text of theNewDoc to theText
print theNewDoc
end tell
jamesabomb wrote:
set CSZ to theCity & ", " & theState & " " & theZip
activate application "TextEdit"
tell application "System Events"
keystroke theName
keystroke theStreet
key code 36
keystroke CSZ
and got city-state-zip correct:
Kansas City, KS 66160
But the remaining bug is for multi-line street addresses, it's not implementing the carriage return, even though the Address Book script library says "Street part of the address, multiple lines separated by carriage returns."
so I'm getting:
University of Kansas Medical CenterDepartment of Neurology3901 Rainbow Blvd.
when I of course want:
University of Kansas Medical Center
Department of Neurology
3901 Rainbow Blvd.
Any ideas?
set theAddressString to theName & return & theStreet & return & CSZ
tell application "TextEdit"
set text of document 1 to theAddressString
end tell
jamesabomb wrote:
I see, but I'm putting the address into an already made document, so I think I have to do it this way. I formatted the address book on the same mac I'm using for the applescript and it still doesn't make the line breaks on multi-line street addresses. Now, I'm typing on a different mac and tried the script on it, same bug, script doesn't do the carriage returns for multiline street addresses.
tell application "Address Book"
--the next 2 lines are to store selected addresses in group envelope that I can drag and drop into a pages merge document to print out all the envelopes for the day's dictation
add the selection to the group "envelope"
save addressbook
set theContacts to the selection
repeat with thisPerson in theContacts
set theName to name of thisPerson
set theStreet to street of first address of thisPerson
set theCity to city of first address of thisPerson
set theState to state of first address of thisPerson
set theZip to zip of first address of thisPerson
end repeat
end tell
set CSZ to theCity & ", " & theState & " " & theZip
activate application "Macspeech Dictate Medical"
tell application "System Events"
keystroke theName
key code 36
keystroke theStreet
key code 36
keystroke CSZ
end tell
tell application "Address Book"
--the next 2 lines are to store selected addresses in group envelope that I can
--drag and drop into a pages merge document to print out all the envelopes for the day's
add the selection to the group "envelope"
save addressbook
set theContacts to the selection
repeat with thisPerson in theContacts
set FormattedAddress to ""
set FormattedAddress to FormattedAddress & name of thisPerson & return
set FormattedAddress to FormattedAddress & street of (first address of thisPerson) & return
set FormattedAddress to FormattedAddress & city of first address of thisPerson & ", "
set FormattedAddress to FormattedAddress & state of first address of thisPerson & ", "
set FormattedAddress to FormattedAddress & zip of first address of thisPerson
-- my writetomacspeech(FormattedAddress)
end repeat
end tell
writetomacspeech(FormattedAddress)
on writetomacspeech(theAddress)
activate application "Macspeech Dictate Medical"
tell application "System Events"
keystroke theAddress
end tell
end writetomacspeech
set FormattedAddress to FormattedAddress & street of (first address of thisPerson) & return
with these lines
set x to to paragraphs of ( street of (first address of thisPerson) )
set {tid, applescript's text item delimiters} to {applescript's text item delimiters, return}
set x to x as text
set applescript's text item delimiters to tid
set FormattedAddress to FormattedAddress & x & return
applescript for address book