Masters
For all intents and purposes, masters are just a special case of slide objects. For example, to add a new rectangle shape to the master of the currently selected slide, in Visual Basic for Applications (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
--no 'master' property of slide, get slide master of presentation
set theMaster to slide master of active presentation
make new shape at theMaster with properties {auto shape type:¬
autoshape rectangle, ¬
left position:10, top:20, width:30, height:40}
end tellIf you're in normal view, remember that you need to click anywhere in the Slide pane to make it active (have the focus) before you run the script, since
slide of view
doesn't exist, and will cause the next line to error otherwise. If you specify a slide other than by selection, this is not an issue.
An issue arises: The dictionary has no
master
property of slide class corresponding to the .Master you see in VBA. However, the master of any slide in a presentation is the same as the slide master property of the presentation, which you do have. The presentation of the selected slide (there's no property for that) has to be the active presentation. Otherwise, it couldn't be selected.
In the Shape class entry in Microsoft Visual Basic Editor Help, you can see that the AddShapes method adds an AutoShape, specified by a particular MsoAutoShapeType constant, plus four integers to describe its position and size: Left, Top, Width, Height. That's what the VBA code above is specifying.
In the shape class entry in the dictionary (Drawing Suite), you will find an auto shape type property, which is read/write. Taking a look at it, you see a long enumerated list of constants that looks very similar to the MsoAutoShapeType enumerated constants in the Visual Basic Editor Help and Object Browser. Furthermore, it includes an autoshape rectangle constant. Meanwhile the separate shape type enumerated property of shape class has nothing that is the equivalent of or about rectangles. So it's clear that auto shape type enumeration is the one you want, in particular the autoshape rectangle constant.
For the other properties needed for make new shape, it's obvious that left position, top, width, and height are the ones you want. Try them out. The script works. Now insert a new slide: the same rectangle appears. You have been successful in adding a shape to the slide master.
You may be aware that in the Microsoft PowerPoint 2004 for Mac UI, you can have multiple masters called "designs." The Designs Collection has been incorporated into PowerPoint VBA for Microsoft Windows for the last three versions. However, they have not been available for PowerPoint VBA for Macintosh. Since the AppleScript model is a part of the Macintosh VBA model, they are not in AppleScript.
What you can do is apply a design to a presentation from a template by using the apply template command, which is the equivalent of the ActivePresentation.ApplyTemplate (FileName) method in VBA. If the template (represented by the file name parameter) has multiple designs, then presumably they will get applied. You just can't verify afterwards the designs you now have.
Document properties
PowerPoint and the other Microsoft Office applications maintain a set of document properties that contain useful information. To access any of these properties, you need to know the name of the property you're looking for. The following macro gives you a list of them:
Sub ListBuiltInProperties() Dim x As Long On Error Resume Next Debug.Print "BEGIN ====================================" With ActivePresentation.BuiltInDocumentProperties For x = 1 To .Count Debug.Print "Property Number: " & CStr(x) Debug.Print "Property Name: " & .Item(x).Name Debug.Print "Property Value: " & .Item(x).Value Next Debug.Print "END ====================================" End With End Sub
Here's the AppleScript equivalent:
tell application "Microsoft PowerPoint" set theLog to "BEGIN =============================" & return set allDocProps to every document property of active presentation repeat with i from 1 to count allDocProps set theDocProp to item i of allDocProps set theLog to theLog & ¬ "Property Number: " & i & return set theLog to theLog & ¬ "Property Name: " & name of theDocProp & return set theLog to theLog & "Property Value: " ¬ & value of theDocProp & return end repeat set theLog to theLog & "END =========================" & return end tell theLog
Note that document property refers just to the built-in ones, although there's no "built-in" in the name of the AppleScript class. In AppleScript, because document property is an element of the application, every document property gets all of them. (There appear to be 30.) This class is found in the Microsoft Office Suite in all of the Office applications. Adding some custom properties in the UI does not add them to every document property.
Once you know the name of the property you're looking for, you can work with it. To display the value of a particular DocumentProperty, such as Template, in VBA:
With ActivePresentation
MsgBox .BuiltInDocumentProperties("Template").Value
End WithThe AppleScript equivalent is:
tell application "Microsoft PowerPoint" set templateValue to get value of document property ¬ "Template" of active presentation if templateValue missing value then display dialog templateValue else display dialog "There is no Template: ¬ this presentation is " & ¬ "based on a Blank New Presentation" with icon 2 end if end tell
The
template
property value seems to be
missing value
(that is, it doesn't exist) whenever your presentation is not based on a template that you have created or imported into your My Templates folder (or a subfolder of Templates folder) by selecting it in the Project Gallery. This is also true in VBA, but there you get a blank MsgBox. In AppleScript, you get an error message, so it's better to trap the error and provide a better message dialog box.
The Template property is read-only; you can't change it. Other properties like Author are read/write. To change the value of a read/write property in VBA, you'd do the following:
With ActivePresentation
.BuiltInDocumentProperties("Author") = "Your Name Here"
End WithIt should have your name by default already. (All Office applications know to look in the Microsoft Entourage Address Book for the "Me" contact and use your name there for the Author document property.) But if you want a better version, say for business purposes, here's the AppleScript you could run on every commercial presentation you make and send out:
tell application "Microsoft PowerPoint" set value of document property "Author" of active presentation to ¬ "Phyllis Harris, Manager" end tell
To see it, on the File menu, click Properties, and then click the Summary tab.


