无法保存到创建的文件夹(applescript)

时间:2016-05-26 16:41:20

标签: scripting applescript

所以我一直在尝试创建一个脚本,在我的桌面上创建一个文件夹,然后创建一个电子表格,并将电子表格保存到所述文件夹。这是剧本......

set folderName to "Tester"
set FileName to "MayDay"
set SaveName to FileName & ".numbers" as string
set FilePath to "Macintosh HD:Users:Ryan:Desktop:" & FileName & ":"
tell application "Finder" to make new folder at desktop with properties {name:folderName}
tell application "Numbers" to activate
tell application "Numbers" to make new document with properties {name:FileName}
tell application "Numbers"
    tell document 1
        tell table 1 of sheet 1
            merge range "B8:C8"
        end tell
    end tell

    delay 1
    tell application "Numbers" to activate
end tell
tell application "Numbers" to (save document 1) in FilePath
end

制作文件夹,打开电子表格,更改名称和合并单元格没有问题,当我尝试保存它时,问题最终会出现。

我在save命令后尝试添加(作为数字)没有括号,这出错了。在我运行脚本并清除崩溃后,我可以关闭数字,它会提示我将其保存在" Tester"文件夹,但它不会自己做。在这里插入白发和头痛。

我对applecript很新,我希望这只是一个简单的语法,任何帮助都会受到赞赏。

提前致谢!

[R

1 个答案:

答案 0 :(得分:0)

这是工作代码。关键是使用 POSIX路径 POSIX文件以及"保存...在..."采用文件引用,而不是字符串。

set folderName to "Tester"
set fileName to "MayDay.numbers"

set FilePath to (path to desktop as string) & folderName & ":" & fileName

set posixPath to POSIX path of FilePath

try
    tell application "Finder" to make new folder at desktop with properties {name:folderName}
on error errMsg
end try

tell application "Numbers"
    set myDoc to make new document with properties {name:fileName}
    tell myDoc
        tell table 1 of sheet 1
            merge range "B8:C8"
        end tell
    end tell

    delay 1

    save myDoc in POSIX file posixPath

end tell