• 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 111



to recipients:"myboss@myCompany.com, hisboss@myCompany.com"

Now if you take a good look at the draft window entry in the dictionary, you will not discover any attachment property! Yet the code works. That is because the developers made a coercion to make things simpler: a putative property for use only at inception, in the with properties parameter of the make new draft window (or draft news window) or outgoing message commands. It doesn't work anywhere else. attachment is actually an element, not a property, of draft window and message classes, since there can be any number of them, from 0 to many.

If you want to get the attachments of an incoming or sent message, you can't get the attachment: you'll get an error. Instead you have to get attachments or every attachment of message, and then get the file property of each one if you want to track them down.

Getting back to our draft window (new message window), you could add the attachment after the fact this way:

set newMsg to make new draft window with properties {subject:"Today's File"}

make new attachment at newMsg with properties {file:alias filePath}

But if you have a lot of attachments to make, this would get tedious. Using the with properties parameter of make new draft window, you can attach a whole raft of attachments, using a list of aliases in { } list braces as the attachment property. You'll also notice we omitted a large number of draft window properties in our code: account, bounds, encoding, priority, and much else we didn‘t need to set. They all have default values, and do not need to be specified, but should we want to change any of them, we can do so.

Make a new Outgoing Message (in the background) and send it

Now how about really automating this process? If you have to send these documents as email attachments every day, and no special customized text message needs to be written each time, you can write a script to send it off all without interruptions of any kind; it's easy to do. Instead of making a draft window, make an outgoing message, and send it off without even bringing Entourage to the front – just stay in whatever application you're in.

Now if you look in the Entourage dictionary, you'll see that recipient is an element, not a property, of message (and of both its subclasses outgoing message and incoming message). That makes sense, since you can have several recipients (of all types, including To, CC, and BCC). And when you want to get the recipients of a message (incoming, or sent, for example), that's how you go about it: every recipient of theMsg . (We‘ll get into how you select the message a little later.) Then you delve into the recipient properties to get the email address and any display name – we'll get into that soon too.

You'd expect that when making a new outgoing message, you'd have to make each recipient at the new message just after making the message – the normal process for creating elements "at" an object. However, it can't be done with outgoing message. The reason is that once a message (as opposed to a draft window) is made, it's "encoded" for the Internet, and its internal structure cannot be modified. Fortunately, the developers again have implemented a coercion – another "putative" recipient property, just like the putative attachment property we've already seen.

Only this time it's essential: it's not a convenient alternative method – this time it's the only method. And it's not documented anywhere, except here. So make sure this one sinks in. Once again, it is only available at inception, when calling make new outgoing message with properties.

Both properties – address, recipient type – listed under recipient class in the dictionary – are available. The address property's type is the rather confusing address class, which in turn has another, different address (text) property – the actual email address – plus a display name text property as well If you are just sending to a single to recipient, you can omit a lot of the specifications, taking advantage of the fact that to recipient is the default recipient type, and you can also use a "Display Name <eaddress@domain>" shorthand (< > angle brackets around the email address) instead of the more complex recipient record structure. This handy coercion is also undocumented:

 

 

tell application "Microsoft Entourage"

     launch -- in background

     set theMsg to make new outgoing message with properties ¬

          {subject:"Today's File", content:¬

              "Please find today's .pdf file attached.", recipient:¬

              "Joe Blow <joeblow@aol.com>", attachment:alias filePath}

     send theMsg



< 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