【问题标题】:PowerPoint Applescript Menu giving different result than AppleScript EditorPowerPoint Applescript 菜单给出的结果与 AppleScript 编辑器不同
【发布时间】:2013-09-11 22:56:03
【问题描述】:

以下脚本在 AppleScript 编辑器中运行时,会以文本形式返回页面上对象的自选图形类型。但是,当从 PowerPoint 中的 applescript 菜单运行时,它会返回一个脚本常量。

我正在使用一个更复杂的版本来根据对象的自动形状类型将对象的属性发送到不同的应用程序......表格放在一个地方,占位符另一个,矩形等到第三个。我也在 PPT 中启动它以推出数据,并且不能真正从任何其他应用程序中提取它,所以 AppleScript 菜单将是我想要的位置。

谁能告诉我为什么同一个脚本会给出两个结果?

谢谢, 亚历克斯

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

结束获取属性

【问题讨论】:

    标签: applescript powerpoint


    【解决方案1】:

    将常量(或标准 applescript 无法理解的应用程序属性)转换为文本很棘手。我的猜测是,当在 powerpoint 菜单中时,脚本可以更好地理解常量,因此您会看到。

    无论如何,我在 Finder 常量方面遇到了同样的问题,并决定自己使用 if 语句处理转换为文本的问题。这是一个繁琐的解决方案,因为您必须考虑每个常数,但至少您知道它会正确发生。

    这是一个例子。假设有一个形状常数“rect”代表矩形,“circ”代表圆形。

    注意:您可能可以使用实际属性的名称而不是代码中的常量。

    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
    

    【讨论】:

    • 不幸的是,无论对象的形状类型是表格、矩形、文本框还是梯形,PPT调用脚本都会在警报中显示“常量****å”。你的脚本有效吗?当我尝试保存它时,它不会编译 > 除非我添加引号。
    • 这只是一个例子来向你展示这个想法。 > 和 > 是您需要放置常量的地方。我实际上并没有尝试脚本。重要的是这个想法。然后你接受这个想法并让它发挥作用。您需要查看 powerpoint 的 applescript 字典以找到可能的形状类型。
    猜你喜欢
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 2011-04-02
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多