Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Using Applescript to auto-address letters in TextEdit

Using Applescript to auto-address letters in TextEdit
Thread Tools
cpac
Professional Poster
Join Date: Jul 2001
Location: New York, NY
Status: Offline
Reply With Quote
Mar 1, 2004, 02:28 PM
 
hello all - I'm looking for a little bit of Applescript help.

Basically, can somebody tell me how (or give me example code on how) to get the data in a specific field of the currently selected record in address book, and have that data writtin in a new TextEdit document?

My ultimate goal is to make a nice little script anybody can use to automatically address a letter. I haven't decided yet whether to have the script create the letter from scratch each time, or to have it rely on the stationary pad feature of the Finder for the basic letter template, but either way it seems like it shouldn't be too difficult to do. I just don't have the Applescript know-how on how to get the data from there to TextEdit.

(If if makes any difference to you offering help, I will post the code of the ultimate result and make it free for anybody who wants to use it - it's just something I'd like to know how to do...)
cpac
     
Diggory Laycock
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Mar 1, 2004, 03:20 PM
 
this should get you started:

Code:
tell application "Address Book" set theSelection to the selection if theSelection is {} then display dialog "Please select a contact in the abook" buttons {"OK"} default button 1 return end if set thePerson to first item of theSelection set theAddress to thePerson's first address set theCity to city of theAddress set theStreet to street of theAddress set theZip to zip of theAddress set theState to state of theAddress set theCountry to country of theAddress end tell set addressText to (theStreet) & " , " & (theCity) & " , " & (theState) & " , " & (theZip) & " , " & (theCountry) & " " tell application "TextEdit" make new document at the beginning of documents set the text of the front document to addressText end tell
     
cpac  (op)
Professional Poster
Join Date: Jul 2001
Location: New York, NY
Status: Offline
Reply With Quote
Mar 1, 2004, 04:01 PM
 
thank you very much! I'll post the finished product once it's ready.
cpac
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:54 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,