張俊芝
張俊芝

Reputation: 387

AppleScript: Get the name of the current font of Microsoft Word

I am new to Applescript, I would like to get the name of the current font of Microsoft Word. I tried the following code:

tell application "Microsoft Word"
    tell selection
        tell font
            name
        end tell
    end tell
end tell

But executing this script prints the following error message:

error: "Can't get name of font." number -1728 from name of <<class w137>>

What's the problem of my code? And what do -1728 and w137 mean?

Upvotes: 1

Views: 120

Answers (1)

wch1zpink
wch1zpink

Reputation: 3142

This works for me using macOS Big Sur and Word version 16.34

tell application "Microsoft Word"
    set fontUsed to name of font object of selection
end tell

Upvotes: 2

Related Questions