0
votes

The following script, when run in AppleScript Editor returns as text the autoshape type of the objects on the page. However, when run from the applescript menu from within PowerPoint, it returns a script constant instead.

I'm using a more complicated version of this to send properties of the objects to different applications based on what auto shape type it is... tables go one place, placeholders another, and rectangles et al to third. I'm also launching this from within PPT to push out the data, and can't really pull it from any of the other apps, so the AppleScript menu would be where I want it to be.

Can anyone tell me why the same script gives two results?

Thanks, Alex

tell application "Microsoft PowerPoint"
    set currentSlideNumber to slide index of slide range of selection of document window 1
    set theSlide to slide currentSlideNumber of active presentation
end tell

getProperty(theSlide)

to getProperty(theSlide)
    tell application "Microsoft PowerPoint"
        repeat with thisShape in (get every shape of theSlide)
          set shapeType to shape type of thisShape
          set shapeContent to content of text range of text frame of thisShape
          display alert (shapeType as string)
     end repeat
end tell

end getProperty

1

1 Answers

0
votes

Converting constants (or application properties which standard applescript doesn't understand) to text is tricky. My guess is that when in the powerpoint menu the script understands the constant better and thus you see that.

In any case, I had the same issue with Finder constants and decided to handle the conversion to text myself with an if statement. It's a cumbersome solution because you have to account for every constant but at least you know it will happen properly.

Here's an example. Suppose there is a shape constant of "rect" which stands for a rectangle, and "circ" standing for circle.

NOTE: you can probably use the name of the actual property instead of the constant in the code.

to getProperty(theSlide)
    tell application "Microsoft PowerPoint"
        repeat with thisShape in (get every shape of theSlide)
            set shapeType to shape type of thisShape
            if shapeType is <<rect>> then
                set shapeTypeText to "rectangle"
            else if shapeType is <<circ>> then
                set shapeTypeText to "circle"
            end if

            set shapeContent to content of text range of text frame of thisShape

            display alert (shapeTypeText)
        end repeat
    end tell
end getProperty