MacTech Network:   MacForge.net  |  Computer Memory  |  Register Domains  |  Printer Supplies  |  Cables  |  iPod Deals  |  Mac Deals  |  Mac Book Shelf


  MacTech Magazine

The journal of Macintosh technology

 
 
The Cross Platform Security Leader

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  Submit a Tip!  
  Get a copy of MacTech RISK FREE  
Google
Entire Web
mactech.com
Mac Community
More...
MacTech Central
  by Category  
  by Company  
  by Product  
MacTech News
  MacTech News  
  Previous News  
  MacTech RSS  
Article Archives
  Show Indices  
  by Volume  
  by Author  
  Source Code FTP  
Inside MacTech
  Writer's Kit  
  Editorial Staff  
  Editorial Calendar  
  Back Issues  
  Advertising  
Contact Us
  Customer Service  
  MacTech Store  
  Legal/Disclaimers  
  Webmaster Feedback  

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 110



          save frontDoc in filePath

     else -- already saved as file, can't re-save (bug)

          beep

          display dialog "Due to a bug in PowerPoint, you need to make sure you " & ¬

              "have saved the presentation first." & return & return & ¬

              "If you have done so, click \"Proceed\"." buttons ¬

              {"Cancel", "Proceed"} with icon 2

          set filePath to full name of frontDoc

     end if

end tell

(You'll note that PowerPoint has another bug. Hopefully, that will be fixed in Office 2008 and you can then remove the display dialog and replace the else section by the same as the equivalent bit in the Excel code.)

Make a Draft Window (message window open on screen)

OK, now that we have the filePath of the front document (as text) we can proceed to make our email message. If we want to open a new message in Entourage, preset to recipients "My Boss" whose email address is "myboss@myCompany.com" and "His Boss", email address "hisboss@myCompany.com", and include a CC to "My Colleague", email address "mycolleague@myCompany.com", with a salutation ("Hi, Everyone") in place, a subject "Today's File", and your usual default signature, the script would now continue:

 

tell application "Microsoft Entourage"

     activate

     set mySigType to default signature type of default mail account

     if mySigType is other then set mySig to default signature choice ¬

          of default mail account

     set newMsg to make new draft window with properties ¬

          {subject:"Today's File", to recipients:¬

              "My Boss <myboss@myCompany.com>, " & ¬

              "His Boss <hisboss@myCompany.com>", CC recipients

              "My Colleague <mycolleague@myCompany.com>", content

              "Hi, Everyone" & return & return, signature type:¬

              mySigType, attachment:alias filePath}

     if mySigType is other then set other signature choice of newMsg to mySig

end tell

 

Note that we activate Entourage to bring it to the front, and that we have to extract the default signature of the default account to be able to use it when we make a new draft window. Checking the dictionary for any type of mail account (POP account, IMAP account, Hotmail account, Exchange account) you will notice that the default signature type might be random, none or other. other is the regular sort of signature: in that case you also have to extract the other signature choice, which is the actual signature. But if your account uses a random or none type, then there is no other signature choice, so we can't specify it later when making the new draft window or the script will error.

The need to use short lines with the continuation character ¬ in this article obscures the fact that the to recipients property (and cc recipients and bcc recipients properties as well) is just a continuous, single string, with the various recipients separated by commas. I.e., when you write your own scripts you wouldn't bother with the continuation character ¬ and would let Script Editor wrap the whole make new draft window command, with the to recipients property specified as:

to recipients:"My Boss <myboss@myCompany.com>, His Boss <hisboss@myCompany.com>"

You do not need to include the display names if you don‘t want to, for any recipients, and in that case you don't need the < > angled brackets around the email address either. So the line above could be written as:



 


Click here to find out more about our best subscription bundle deal ever!
2 years of the magazine, and the all new MacTech DVD ... at 70% off!



Click on the cover to
see this month's issue!

TRIAL SUBSCRIPTION
Get a RISK-FREE subscription to the only technical Mac magazine!
 
 


MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797

Register Low Cost (ok dirt cheap!) Domain Names in the MacTech Domain Store. As low as $1.99!
Save on brand compatible and name brank ink jet and laser supplies.
Save on long distance * Upgrade your Computer
Movies with No Late Fees!

See local info about Westlake Village
SJ * BRJ * BJ * OJ * NITS
Staff Site Links



All contents are Copyright 1984-2008 by Xplain Corporation. All rights reserved.

MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central 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.