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



          end repeat

          set AppleScript's text item delimiters to {""}

         

          display dialog (text 3 thru 8 of (get content))

         

     end tell

end tell

First up is something rather trivial, but it could cause you a bit of confusion. I had to change the counter in the repeat loop from x to i : it seems that x and y are defined somewhere in the PowerPoint dictionary (it turns out to be as constants of an enumerated property property of the property effect class, used for animation behavior). That means they will not compile as variables: you get an AppleScript Syntax Error: " Expected variable name or property but found application constant or consideration." A most unfortunate choice of constant name.

Next, all those "compound" lines where a display dialog command is targeted at the content of the text frame require an explicit get before content, or they raise the peculiar error "Can't make content of text frame…into a string" which could make you think that the problem is with the Unicode text that PowerPoint uses. But no – display dialog has accepted Unicode text since Panther, although it used to be an issue previously. (Also coercing 'as string' works which would seem to confirm that impression, but that's just because the coercion forces an evaluation, like get does.)

A distinct difference of display dialog, as opposed to VBA's MsgBox, is that you definitely need to get the content property of character, word, text flow, etc. display dialog will error if you try to get it to use the object reference itself. (This is another instance of VBA objects often having Default properties – in this case Words(Index), etc., in VBA returning a TextRange with a default Text property, while Applescript, which does not have default properties, having to explicitly get the content of word i, etc.) Over in VBA, a coercion (along with the default property) allows you to MsgBox (and Debug.Print too), a Character, Word and Run without casting them to string explicitly. Both MsgBox and display dialog accept numbers, however (display dialog only since OS 10.4), and coerce them to string for you.

Finally, when getting the color of the font (or of anything else) in AppleScript, it is not returned as a single number (Long) as in VBA: a list of three integers is returned. That's all very well, but display dialog cannot display lists. Since we precede the list {0, 200, 100} by a string, the concatenation operator & coerces the list to a string implicitly without our having to write 'as string'.

When lists of strings are coerced to a string, explicitly or implicitly, text separators are inserted between the list items: these are AppleScript's text item delimiters, a language global. The default delimiter is "", i.e., nothing is inserted between the list items. So if we didn't change the delimiter to something visible a list of three integers such as {0, 200, 100} would coerce and display as "0200100". Using ", " as the delimiter, we get "0, 200, 100" and if we add brace characters "{", "}" around that string we get "{0, 100, 200}" which looks exactly like a list in display dialog. After using them we must restore the text item delimiters to what they were before, or to the default {""} since they remain active in the application running the script, for all other scripts too (at least in Script Editor, and in all script menus, although not in Script Debugger) until you change them again. Incidentally, they are theoretically a list of delimiters which is why list braces {""}, {", "}, etc. are used around them, but in actual fact only the first list item is used and you can omit the braces if you wish.

Masters and Properties

Working with masters

Masters are really just a special case of slide objects, for all intents and purposes. For example, to add a new rectangle shape to the master of the currently selected slide, in VBA:

Sub AddShapeOnMaster()

 

With ActiveWindow.Selection.SlideRange

   ' Make a new shape in the slide's Master instead of the slide itself

Call .Master.Shapes.AddShape(msoShapeRectangle, 10, 20, 30, 40)

End With

End Sub

Here's the AppleScript equivalent:

tell application "Microsoft PowerPoint"

     --get the selected slide: make sure slide pane is active

     set theIndex to slide index of slide of view ¬

          of active window

     set selectedSlide to slide theIndex of active presentation



< 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