收藏计数但无法访问项目

时间:2019-01-10 19:24:12

标签: applescript

我正在尝试通过AppleScript自动化MS PowerPoint。我想获取活动窗口的(形状)选择。阅读字典,我的猜测是:

tell application "Microsoft PowerPoint"
    set sel to shape range of selection of active window

    count of sel's shapes -- returns 2 for specific case
    -- class of sel's shapes -- throws a compilation error "object you are trying to access does not exist"
    set i to item 1 of sel's shapes -- i not set but this line does not throw an error
    i -- error: the variable i is not defined
end tell

,带有注释,指示运行特定行时会发生什么。有趣的是,sel's shapes确实有一个计数,但是我无法从中获取任何项目。我的第一个直觉是sel's shapes必须是其他数据类型,但是class sel's shapes也会引发错误,抱怨sel's shapes不存在。

问:这是怎么回事?在count ofitem 1 of未定义的情况下,如何定义class of(并起作用!)?

1 个答案:

答案 0 :(得分:1)

事实证明,这是由于AppleScript(https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_reference_forms.html#//apple_ref/doc/uid/TP40000983-CH4g-120522)中引用表单的处理方式所致。

在这种情况下,“形状范围”不包含任何“项目”。它仅包含“形状”:

set s to shape 1 of shape range of selection of active window

工作正常:

s's left position -- Returns an actual value

经验教训:请小心使用要从集合中获取的正确类别的物品。