【问题标题】:Cannot edit numbers document with AppleScript无法使用 AppleScript 编辑数字文档
【发布时间】:2020-04-24 15:58:24
【问题描述】:

我正在尝试在 automator 中为苹果程序编号运行一个非常简单的脚本。我尝试了几个不同的脚本都没有成功。

使用以下代码:

on run {input, parameters}

    tell application "Numbers"
        activate

        tell document 1 to tell sheet 1 to set the value of cell "B3" to 0
        tell document 1 to tell sheet 1 to set the value of cell "C4" to 42

    end tell

    return input
end run

我收到以下错误消息:

“数字出错:无法将文档 1 的工作表 1 的单元格“B3”设置为 0。”

发布的问题与以下解决方案几乎相同:

on run {input, parameters}

    tell application "Numbers"
  tell table 1 of sheet 3 of document 1
    set the value of cell 1 of column "E" to 1000
  end tell
end tell

    return input
end run

但这给了我以下错误信息:

“编号出错:无法将文档 1 的表 1 设置为 1000。”

这篇其他帖子确实提到它可能与特权有关,但没有详细说明,我无法找到有关此的更多信息。

谁能帮帮我?

谢谢。

【问题讨论】:

    标签: numbers applescript


    【解决方案1】:

    Numbers 文档已经打开,下面的示例 AppleScript 代码为我工作:

    tell application "Numbers"
        activate
        tell first table of first sheet of front document
            set value of cell "B3" to 0
            set value of cell "C4" to 42
        end tell
    end tell
    

    下面是与上面的示例 AppleScript 代码相同的不同方式:

    tell application "Numbers"
        activate
        set value of cell "B3" of table 1 of sheet 1 of document 1 to 0
        set value of cell "C4" of table 1 of sheet 1 of document 1 to 42
    end tell
    

    注意:示例 AppleScript 代码就是这样,不包含任何错误处理可能是适当的。用户有责任根据需要或需要添加任何错误处理。查看AppleScript Language Guide 中的try statementerror statement。另请参阅Working with Errors。此外,在适当的情况下,可能需要在事件之间使用delay 命令,例如delay 0.5延迟设置得当。

    【讨论】:

    • 这行得通。也许这是指向“文档”而不是“前端文档”的问题。非常感谢您的及时回复和帮助。
    • @Michael Szabo,您问题中 code 的第一个 block 的问题是它缺少 table,例如first tabletable 1 它们是相同的,只是说同一件事的两种不同方式,如 front documentdocument 1code 的第二个 block 只有在 document 1 中存在第三个 sheet 并带有 table 时才有效。对我来说,code 的第二个 block,按原样,只有一张 sheet 出错:“error “数字出现错误:无法获取文档 1 的表 3。无效的索引。”文档 1 的表 3 中的数字 -1719”如果我将 sheet 3 更改为 sheet 1 它可以工作。
    • 感谢您的澄清。
    • 你可能知道这个问题的答案。无论如何要在 iPhone 或 iPad 的 Numbers 应用程序中添加复选框和脚本以显示/隐藏行?我似乎无法在任何地方找到有关此的信息。
    猜你喜欢
    • 2011-03-15
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多