0
votes

I want to change Western and Asian font settings of selected text in a PowerPoint (2011 Mac) slide with AppleScript. Something like the following should work, according to this. However, I can't even get text range of selection, let alone name of font.

tell application "Microsoft PowerPoint"
    tell active window
        set name of font of text range of selection to "Palatino"
        set east asian name of font of text range of selection to "YuMincho"
    end tell
end tell

Here is the result.

error "Can’t get text range of selection." number -1728 from «class TObj» of «class SelO»

In effect, the following issues the same error.

tell application "Microsoft PowerPoint"
    tell active window
        get text range of selection
    end tell
end tell

On the other hand the following simple VBA code works fine.

Sub HiraginoSansW2HelveticaNeueLight()
    With ActiveWindow.Selection.TextRange.Font
        .Name = "Palatino"
        .NameFarEast = "YuMincho" 
    End With
End Sub

Essentially, the VBA does what I want, but it involves enabling Macro and saving in .pptm format rather than standard .pptx, etc. It's not as handy as AppleScript, which I can access from menu bar.

Could anyone help me get the AppleScrit work?

2

2 Answers

1
votes

Some commands need to specify the window (even in a tell active window block)

Use its or of it, like this:

text range of selection of it
text range of its selection

Information of an AppleScript's term in Powerpoint: use font name of font instead of name of font

1
votes

The following code worked well.

tell application "Microsoft PowerPoint"
    tell active window
        set font name of font of text range of selection of it to "Arial"
        set east asian name of font of text range of selection of it to "游明朝体"
    end tell
end tell