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



The message will appear automatically with the default signature you use for that account. So don't add it to the message content or it will appear twice. If you want to change it for this message, you need to change the default signature type and default signature choice of the account first (or to 'none' signature type and add the text you want to the message content) and then change it back after you make the message.

outgoing message is a subclass of the generic message class (with extra properties not sensible for received incoming messages), and inherits a few read-only properties that are appropriate only for (your own) messages after they are sent – such as forwarded, redirected, replied to, resent. Don't set them for a new message, even though most read-only properties can actually be set at inception if you really need to.

connection action is something only normally applicable to incoming POP messages. Probably it should have been made a property of incoming message class, not message. Don't try to set that for a new message either. edited really and truly is read-only and can't be set by script, ever.

color is a mistake, and is deprecated (inherited from Outlook Express). Don't try to set it: it's been replaced by category – each category has a color property which can be set. category property here is a list of categories {category "Work", category "Personal} since messages and other objects can have more than one category (the first one listed is primary and sets the color). Or it can be an empty list {} for no categories: there is no category "None"! The default is {} which does not need to be set.

Normally you will not set source, but you would if trying to duplicate another message (with perhaps a few differences which you set separately). source is the entire structured message text, parts, attachments, and headers. You wouldn't normally try to script headers either: let them be formed automatically.

All other properties can be set. has html could be set to true at inception – the default is false – but that just determines that your default HTML font and size will be used. Entourage does not have any way to script formatted text. And for some reason setting has html to true removes carriage returns from the message content, so don't do it.

Basically, stick to the properties marked in the dictionary as read-write. If you don't specify where to make the message, it gets made at your Drafts folder. The alternate location you might prefer to specify would be the outbox. Here's a typical example:

tell application "Microsoft Entourage"

     -- add carriage returns before signature used for the account

     set theBody to "Some long text here. As long as you want." & return & return

     set theMsg to make new outgoing message at outbox folder with properties ¬

          {account:POP account "My Account", subject:"My New Message", content:¬

              theBody, recipient:"Joe Blow <jblow@aol.com", flagged:¬

              true, priority:high, category:{category "Work"}}

end tell

Make an incoming message

You might wonder what would be the point of making a new incoming message, since those are messages you receive from others. You wouldn't think it would even be possible. In fact, it's a way of importing messages into Entourage. (The import command is so far just valid for .mbox files, which become message folders.)

You could read the content of an .eml message file, in a way similar to reading a .vcf file in “Attach a vCard” later in this chapter, and use that as the source property – the only property you'll need – to make a new incoming message at any folder. Or to make a duplicate message from properties of an existing message at a location where duplicate does not work.

The interesting thing is that this is possible by AppleScript, although not in the UI. Most of the so-called read-only properties are settable at inception, so you can do almost whatever you want with the power of AppleScript. Just follow the same sort of procedure as making an outgoing message, but do it as an incoming message, to see for yourself.

Email: Selecting Messages, Running Scripts from Rules, Schedules, Menus

Sometimes the email scripts you run will be on received messages. You may have seen that Entourage's Rules (in Tools menu) can be enabled to run automatically on messages as they come into the Inbox, and one of the possible Actions they can perform is to Run AppleScript. Similarly, Schedules (also in the Tools menu) can be set to perform tasks on a regular repeated schedule, or at startup or on quit, and can also Run AppleScript. Both of these provide a very high degree of customization and automation, since AppleScript can do "almost anything" with Entourage's objects, far more than standard Rule and Schedule actions can do, and also with a far finer degree of selection and combination.

You may have found a certain degree of frustration with rules that let you filter when "all criteria are met" (i.e., boolean AND for all conditions) or when "any criteria are met" (i.e., boolean OR for all conditions) but no finer or more complex granularity: AppleScript can handle any degree of complexity, so just write it as a script and run the script from the rule.

Before we get to some more examples, there's one thing, not fully explained in the Entourage dictionary, that needs to be dealt with. It will come up again and again in your Entourage scripts. How do you specify the selected message(s) on which you want to run a script, and how do you specify the message on which the running rule should operate? By the same application property – current messages – which is always a list of messages.



< 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