You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 17:39:03