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



          reply to theMsg attribution style no attribution ¬

              html text htmlText

     end if

end tell

The first part of the script checks to see whether you are replying to a message viewed in the Preview Pane of the main window, in which case it will be our good friend

   item 1 of (get current messages)

since the message viewed in the preview Pane is the message selected in the message list, i.e., the first (and only) of current messages. If not, it checks to see if the class (type) of window in the front is a message window, (meaning a window showing a saved message, not a "new message" draft window), and if so, it gets the displayed message of the window.

It then checks to make sure you have selected or opened a received message by checking for incoming message class. If the front window is neither the main window nor a message window, or if the class of the message is not incoming message, it invokes an error number -128 (equivalent to "Cancel" and thus a safe error to invoke), which it then catches in the on error block and displays a dialog to alert you and quits the script (return) when you click OK. The reason it goes about it in this fashion (invoking an error instead of just displaying the dialog and quitting in the appropriate else and if statements) is in order to also catch a true error if there is no window open at all, and also to only have to call the display dialog once, no matter which condition causes it.

If all is well, the script continues to the next if block to check if you're replying to an HTML message in the case that your preference is replyUsingMessageFormat, and if so sets the htmlText property to true as well. Finally, it moves on to call the reply to command with the appropriate parameters for attribution style and html text depending on your preferences (set properties).

A third, optional, parameter for reply to, namely opening window is true by default so does not need to be specified, and therefore a new draft window with recipient, quoted text and attribution all set to go opens immediately. (Setting opening window to false is the technique to use when you want to set a prepared reply text by the script and just send off the message automatically in the background.)

Save the script to the Entourage Script Menu Items folder in script (.scpt) format, naming it as "Reply Insertion Reversed \cmR.scpt " to apply a keyboard shortcut of control-command-R. (When adding keyboard shortcuts, you need one or more of the modifier keys Command (Apple), Option, Control, Shift. You must avoid shortcuts already taken by Entourage, other scripts, or the OS. Control is a good modifier key to include because the built-in Entourage shortcuts virtually never use it.)

The version of the script at scriptbuilders.net includes a second script "Reply All Reversed" which does the same but as Reply To All. To make one yourself, just copy and paste the script above into a new script window and add with reply to all to each of the reply to lines at the bottom:

if attributionStyle = "short headers" then

          reply to theMsg attribution style short attribution ¬

              html text htmlText with reply to all

     else if attributionStyle = "internet" then

          reply to theMsg attribution style internet attribution ¬

              place insertion point on top insertionPointOnTop ¬

              html text htmlText with reply to all

     else -- no attribution

          reply to theMsg attribution style no attribution ¬

              html text htmlText with reply to all

     end if

You can save this one as "Reply All Reversed \scmR.scpt " to get a shift-control-command-R shortcut.

Email (and Contact): Adjust Messages before Sending

You may have noticed that none of the Office applications can run scripts automatically when some event occurs in the application: i.e., there are no events available. (This is a loss compared to VBA in the other Office applications, as has been noted.) This is not because AppleScript could not do so – in fact events provide the entire basis of AppleScript Studio which lets you make your own Cocoa applications using AppleScript – but it is extremely rare, almost nonexistent, in scripting applications.

Thus you cannot "intercept" events such as button-clicking or selecting menu items. This is intentional on the part of the application developers as a security measure – they do not want to allow the possibility of malicious interference. So that means that you cannot have a script run automatically when you click the Send Now button. You have likely discovered that the so-called "Outgoing Rules" are really "Outgone Rules": they run only on the sent message after it has been sent, too late to alter anything in it.



< 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