• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition

Introduction  |  Table of Contents

Page Prev and Page Next buttons at bottom of the page.

Would you like a hard copy
or PDF of this Guide?

You can get a hard copy sent to you
AND download a PDF now ($19.95)
, or

... just download a PDF ($9.95).

Either way, you get a complimentary
MacTech Magazine Subscription

courtesy of the
Microsoft Mac Business Unit


 

  Magazine Reg. Price:  $50.00 value  
  Guide Reg. Price:  $40.00 value  
  You Save:  over $80.00!  

April, 2007
Page 130



          repeat with toRecip in (every recipient of theMsg ¬

              whose recipient type is to recipient)

              set {dName, eAddress} to {display name, address} ¬

                   of (address of toRecip)

              if dName ­ "" then

                   set nameAddress to "\"" & dName & "\" <" & eAddress & ">"

              else

                   set nameAddress to eAddress

              end if

              if {eAddress} is not in entryAddresses then

                   make new group entry at theGroup ¬

                        with properties {content:nameAddress} -- note content syntax!

                   set end of entryAddresses to eAddress

              end if

          end repeat

     end repeat

     beep 2

     open theGroup

end tell

The script first asks you to name the new group; note that default answer:"" is the way to include a blank text box in display dialog: check for more options in the display dialog entry in the Standard Additions dictionary. The variable groupName is set to text returned of result (what you type in the text box). Then you are asked whether or not you wish to allow the group to list names and email addresses, corresponding to the similar checkbox you will find in the UI of every group in the address book when you open its window, and sets the variable showOnlyName to true or false depending on the answer.

Then we make the new group, assigning it the variable theGroup, specifying its name and show only name in messages properties with the variables we previously assigned for those values. We get the selected messages – you can run the script on several messages at once if you wish, or just one (as we know already, current messages is always a list, even if just a single-item list) – and then process each item of the selectedMessages list (each message) ­in the repeat loop.

Before starting the outer repeat loop, we initialize an empty list entryAddresses, to which we will add entries as we make them. By setting it only once, outside the outer repeat loop, we insure that duplicate contacts will be avoided for all the messages being processed.

Within the outer repeat loop (for each message) we now proceed to the inner repeat loop for each to recipient of the message. (If you want to include cc recipients as well, simply remove the whose recipient type is to recipient clause.)

We now delve into the peculiar structure of the recipient class once again, whereby its address property is in fact a record containing both a different address property (a string this time, namely the actual email address) and a display name property which might be "" (blank) if not included in the message, and assign the variables eAddress and dName to them respectively. We then need to check whether the display name is in fact present or missing, since if it is not blank (dName ­ "") we include it followed by a space and the email address in < > brackets when assigning the nameAddress variable; if the display name is blank (else) we include only the email address on its own.

Note the extra quotes we put around dName if present: that is required in Entourage if the display name happens to contain any punctuation (such as a period after an initial) – which would otherwise error further down the script when creating the group entry – and it does no harm if there is no punctuation: in fact, in that case, you will not even see the quotes around the display name in the UI since they are removed automatically if not needed.



< Previous Page Next Page>
 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live