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 92
In VBA the only argument that can be specified with Presentations.Add is WithWindow that determines whether the new presentation is visible or not. There is no way to make an invisible presentation in AppleScript, since presentation does not have a visible property to set to false. (Its main document window does, but as with many applications, the visible property of document window is read-only, and is always true.) Nor is there any command such as hide. So invisibility is something you have to give up, if you were ever accustomed to making invisible presentations (for speed) in VBA.
At first there seem to be no properties of a presentation that you can set as such in AppleScript (the dictionary entry for presentation shows all properties as r/o: read only) but don't be dismayed – there are many properties, such as page setup, web options. slide show settings, etc. that return objects whose own properties can be set with abandon and almost infinite choices. This is similar in every Office app: it means you can set these 'properties of properties' after creation of the presentation but not in a 'make new' statement. There are also new elements that can be made at the presentation, also after creation of course, and then you can modify them (i.e. set the elements' own properties) as needed.
Don't forget that what VBA considers Properties includes many Collection Objects (such as Slides), which in AppleScript are elements that you make. All other properties of presentation, both in VBA and in AppleScript, are read-only, aside from a very few (east asian line break level, layout direction, and a few others) that the PowerPoint AppleScript Reference informs us are not available in U.S. English version of PowerPoint in any case. The one real gap in AppleScript, which somehow got omitted, is an equivalent to the DisplayComments property, which is a read/write property and should be controllable from AppleScript. You can make comments (in the Drawing Suite) and set all sorts of attributes for them, but not control whether they are visible or not.
So every script that needs to make a new presentation will start off, simply, as
tell application "Microsoft PowerPoint"
set newPres to make new presentation
tell slide 1 of newPres
-- code here
end tell
end tell
You must set a variable of your choice to the make new presentation statement, which by definition returns the object it has made, or you won't have anything to work with. Of course you won't always be going on to tell slide 1 (to set various properties of, and make new elements at, slide 1), but you will get around to that pretty soon in most cases. We will be looking into what can be done with presentations and slides in a moment.
Open an Existing Presentation
It's a relief to say that opening an existing presentation .ppt file is, as with all applications, dead simple in AppleScript. The equivalent of the Open method in VBA:
Presentations.Open FileName:="Mac HD:Folder:Filename.ppt"
is the open command (in the Standard Suite) in AppleScript:
tell application "Microsoft PowerPoint"
open alias "Mac HD:Folder:Filename.ppt"
end tell
Note that you should properly use the alias reference form, but the PowerPoint developers have enabled a coercion allowing you to use just the path text as an equivalent, just as in VBA. Also, in AppleScript, you can open a list of (presentation) files all at once if you wish. – just provide the list of .ppt aliases.
Sometimes we are interested not just in opening a presentation, but also in modifying it, or getting some information from it. In VBA, that is very straightforward: you just set a variable (reference) to the result of the Open statement, which returns a Presentation object, and then set some Properties of it or apply some Methods to it:
Dim oPres As Presentation, oSlide As Slide
Set oPres = Presentations.Open(Mac HD:Folder:Filename.ppt")
With oPres
Set oSlide = .Slides.Add(2, ppLayoutText)
End With
The process of setting a variable to the result of a command is usually straightforward in AppleScript too. However, just as in Word, the command open from the Standard Suite does not return a result, so you cannot set a variable to the command. They would have done far better to do what Excel does – leave the plain open command in place for opening multiple files, and also give PPT its own 'open presentation' command with all the parameters, that does return a result.
Here is a workaround:
tell application "Microsoft PowerPoint"
open "Mac HD:Users:yourname:Desktop:Saved Pres.ppt"
set thePres to active presentation
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine