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 of
定义(和工作!)whileitem 1 of
和class of
not?
解决方案
事实证明,这是由于 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
经验教训:注意使用您尝试从集合中获取的正确项目类别。
推荐阅读
- javascript - 为什么要在类中声明变量,甚至在构造函数中将该变量分配给 this
- spring-boot - Reactive-Spring-Security-5.1.3.RELEASE,多重授权
- android - 如何检查变量是否是Kotlin中的数组
- scala - 没有任务时,为什么 Akka 会关闭调度程序?
- c# - 如何使用 LINQ 从动态列表中选择特定字段
- c# - restResponse sslStream 在完全读取流 C# 之前根据响应进行处理
- reactjs - React Native TouchableOpacity OnPress 不使用循环
- python - 使用 matplotlib 绘制绘图时 X 轴刻度标签太密集
- highcharts - 如何在Highcharts中绘制一个系列既有正值又有负值的条形图?
- angular - 我可以使用 POST 请求检索数据吗?