我正在调整我在 iWork 自动化上找到的代码,以满足我从 AppleScript 导出 PDF 的需求,并且可能遇到了软件的一些限制,但想看看这里是否有人可以提供一些帮助。
问题 1 - 我的电子表格中有 2 张工作表。表号 1 包含任务,表号 2 是引用第一张表填写表格的发票。使用我拥有的代码,它会复制电子表格并删除表格#1,以便仅导出发票 - 这是我在 AppleScript 导出单个表格方面发现的唯一解决方法。我如何能够将公式烘焙到发票表中,以便在删除表 #1 时,内容仍然存在?
问题 2 - 我想在导出的 PDF 上添加一个自定义标签,即“发票待付款”,但据我所知,我们仅限于使用苹果的集成颜色标签,是这样吗?我知道有一个程序'Hazel'可以实现我想要的,但我宁愿自己编写脚本而不是使用另一个应用程序。
问题 3 - 是否有任何方法可以更改此脚本,使其不会在 GUI 中提取数字并在命令行的后台完全运行?
我正在使用的脚本如下所示。
谢谢。
set {year:y, month:m, day:d} to (current date)
set dateString to (d) & "_" & (m as integer) & "_" & (y as text)
set destinationFolder to ("Macintosh HD:Users:Test:Finance:Income:Invoices:" & year of (current date) & ":") as text
set theFile to choose file of type "numbers"
tell application "Finder"
set docName to name of theFile
if docName ends with ".numbers" then ¬
set docName to text 1 thru -9 of docName & "_" & dateString & "_invoice"
set theDuplicate to duplicate file (theFile as text) -- create duplicate
try -- try block, because maybe destination file already exists
make new file at folder destinationFolder with properties {name:(docName & ".pdf")}
end try
end tell
tell application "Numbers"
activate
set Doc to open (theDuplicate as text as alias) -- open the duplicate
delete sheet 1 of Doc
set PDFExportFileName to destinationFolder & docName & ".pdf"
export Doc to file PDFExportFileName as PDF
close documents saving no -- quit without saving
end tell
-- delete the temporary duplicate (if need)
tell application "System Events" to delete file (theDuplicate as text)