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.
|
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>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine