用applescript复制数字表

时间:2014-05-13 12:56:36

标签: macos applescript iwork

我尝试使用AppleScript复制数字文件中的工作表(我每天需要一张基于模板的新工作表)。 我是AppleScript的新手,但是我已经用它来填充一些单元格,这些单元格来自我运行的python脚本,但这一点仍然是手动的... = /

tell application "Numbers"
tell document 1
    set thisSh to make new sheet with properties {name:"May14"}
    duplicate sheet "Template" to sheet "May14"
end tell
end tell

上面的代码会返回错误:error "Numbers got an error: Sheets can not be copied." number -1717,因此,我的问题是:有没有办法复制数字表?

我目前正在使用数字3.2运行iWork

谢谢!

P.S。我还尝试了duplicate every table of sheet "Template" to sheet "May14"类似的错误:Tables can not be copied.

1 个答案:

答案 0 :(得分:1)

您有两种选择。您可以以编程方式在新工作表中构建表,也可以从第一个工作表中选择并复制表,然后将它们(它们)复制到新工作表中。这是第二个选项的代码。如果没有看到模板表的屏幕抓取,您可能需要进行调整,但这应该可以为您提供所需的一切。如果您遇到并发症,请发布模板表的截图和说明。 更新以说明工作表中的疯狂数量的表格。 再次更新以演示如何更改活动工作表。

tell application "Numbers"
    activate
    tell document 1
        set tempSheet to first sheet whose name is "My Template"
        set active sheet to tempSheet
        tell application "System Events"
            -- deselect all
            keystroke "a" using {command down, shift down}
            delay 0.1
            -- select all containers (tables, text items, etc.)
            keystroke "a" using {command down}
            delay 0.1
            -- copy the containers
            keystroke "c" using {command down}
        end tell
        delay 0.1
        set dateString to (month of (current date)) & (day of (current date)) as string
        set thisSheet to make new sheet with properties {name:dateString}
        tell thisSheet
            delete every table
            tell application "System Events"
                keystroke "v" using {command down}
            end tell
        end tell
    end tell
end tell