AppleScript服务读取Numbers选中单元格值写入指定单元格报错求解
AppleScript 修复方案
错误原因
写入目标单元格的代码没有绑定之前定位到的CurrentTable对象,脚本无法识别要操作哪个表格的B2单元格,因此触发写入报错。
修复后完整脚本
on run {input, parameters} global mybox set mybox to 0 tell application "Numbers" tell the front document to ¬ tell the active sheet to ¬ set CurrentTable to the first table whose class of selection range is range tell CurrentTable -- 读取选中单元格的值 set selectedValue to the value of the first cell in the selection range if selectedValue is not missing value then set mybox to selectedValue display dialog "Cell value: " & mybox -- 绑定表格对象后写入指定单元格 set the value of cell "B2" to mybox end tell end tell return input end run
使用说明
- 脚本默认将选中值写入当前表格的B2单元格,如果需要修改目标位置,直接替换代码里的
"B2"即可,比如要写入C5就改成"C5" - 全局变量
mybox已经可以正常存储选中的单元格值,可直接用于后续其他逻辑调用
内容的提问来源于stack exchange,提问作者helpmator
相关产品推荐
相关产品推荐

