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 94
with properties {layout:slide layout text slide}
set newSlideB to make new slide at end of active presentation ¬
with properties {layout:slide layout two objects over text}
set newSlideC to make new slide at before slide 2 of active presentation ¬
with properties {layout:slide layout media clip and text}
end tell
The last command inserts newSlideC as the new slide 2 before the existing slide 2. (You could also say at after slide 1 to insert it at the same location, if you like the sound of that better.) Don't forget – you can't drop the at preceding before – even though it sounds terrible in English. After the slide is created, you can always get its slide index property to find out where it is located.
Now where did those layout types come from? In the dictionary for slide (Microsoft PowerPoint Suite) you will see all the enumerated constants for layout property strung together, separated by / slashes. (Enumerations have a much nicer "layout" in Script Debugger.) It's very easy to see which one must be the equivalent for VBA's ppLayoutText constant: it's obviously slide layout text slide. (AppleScript developers have to be extremely careful not to cause terminology conflicts: the keywords you see in dictionaries and scripts mask the real "raw codes" that the compiler compiles to: if the same keywords were used for different properties and enumerations, scripts would compile incorrectly and fail. The simplest way for the developers to avoid conflicts is to give enumerations a unique name starting with the class and property – slide layout – and only then follow with the enumerated constant. text is used in so many constants of this enumeration – it's the third word in no less than six of them – that they've added the word slide to make sure this one is unique and won't be confused with any of the others.)
You will be able to find the AppleScript version of the VBA constant without difficulty: just precede it by "slide layout" and look for what is virtually the same name. Occasionally you will see macros where the author has used the actual Long (number) rather than the descriptive pp constant: for example for ppLayoutText he might have used the number 2 instead. Unfortunately, in this case that won't work (though in several enumerations in Office it does!). You would need to look up ppSlideLayout in the VBE Object Browser to find its (ppLayoutText) name from the Long (2) first, and then use its obvious AppleScript equivalent from the enumeration list.
Once you've made your slides, you will want to keep track of which one is which, since the canonical reference to slides is by index (slide 1, slide 2, slide 3, etc.) which keeps changing if you insert a new one at the beginning or somewhere in the middle. What you knew as "slide 3" is no longer slide 3, but slide 5, for example.
In VBA, all slides have a Name property (by default "Slide1", "Slide2", etc. but you can rename them). For some reason (this starts to become familiar) there is no name property in AppleScript. However, all slides also have a unique ID, or SlideID property in VBA, which you can get as soon as you've made the slide. (They seem to increment forever from the moment you first launched your copy of PowerPoint.) This property does exist in AppleScript, as the slide ID property. In VBA, you can find the slide again using the SlideID, via the FindBySlideID method of the Slides Collection Object. Such a command does not exist in AppleScript (you start expecting this after a while). But here's where the whose filter of AppleScript comes to the fore. This ought to work:
get first slide of active presentation whose slide ID is 1257
but the result is {} (an empty list = nothing), clearly a wrong result when you know the slide does exist. It's another bug. In fact, the formulation first element whose… is often not quite right in the Office apps: sometimes it gets you the same result as every element whose… instead. (Sometimes it works fine.) The workaround here is to:
get every slide of active presentation whose slide ID is 1257
which gets you the right result:
--> {slide 1 of active presentation}
in list braces. There can only ever be one slide with that ID, so "every" gets you the single-item list. The solution is:
item 1 of (get every slide of active presentation whose slide ID is 1257)
--> slide 1 of active presentation
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine