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


  MacTech Magazine

The journal of Macintosh technology

 
 

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  MacTech Forums  
  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 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



 


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!
 
Nokia Qt Beta
 


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.