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



< 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