我目前有一套Hazel例程,它们都使用相同的AppleScript,包括 infra 。例程执行以下操作:
Folder
并检查Folder
中某些字符串的PDF格式。如果找到匹配的字符串:
使用以下方案重命名匹配的文件:name-email-extension(即,它插入一个在Hazel例程中预定义的电子邮件地址)。
运行AppleScript(再次, infra )。
将匹配的文件移动到存档文件夹。
这是AppleScript:
on hazelProcessFile(theFile)
set theAttachment1 to (POSIX path of theFile)
tell application "System Events" to set {name:Nm, name extension:Ex} to theFile
set FileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
-- parse using —
set {TID, text item delimiters} to {text item delimiters, "—"}
set clientName to text item -3 of FileName
set clientEmail to text item -1 of FileName
set text item delimiters to TID
tell application "Airmail 2"
activate
set theMessage to make new outgoing message with properties {subject:"New Invoice from Company", content:"Please find attached, infra, the current month's invoice. If you have any questions, please feel free to respond to this email. One-time payments may be made using the following secure form on our website: https://example.com/payment/. Thank you for your continued business."}
tell theMessage
set sender to "billing@example.com"
make new to recipient at end of to recipients with properties {name:clientName, address:clientEmail}
make new mail attachment with properties {filename:theAttachment1}
compose
end tell
end tell
结束hazelProcessFile
此脚本解析文件并使用文件名中包含的信息生成电子邮件。一切都按预期工作,除了文件实际上没有附加到电子邮件。我有一个更简单的脚本版本工作,但所有内容都硬编码到脚本中,它不能用于除了设计它的单个客户端之外的任何东西(例如,它实际上有客户端的名称和电子邮件编码到脚本而不是从文件中提取它们。)
以下是触发Hazel例程时控制台中的结果:
2015-12-29 11:50:48.293 hazelworker[1817] Processing folder Invoice Staging
2015-12-29 11:50:50.449 hazelworker[1817] Client—2015-12-29-2015-INV-1000393.pdf: Rule To Be Emailed matched.
2015-12-29 11:50:50.449 hazelworker[1817] [File Event] File moved: Client—2015-12-29-2015-INV-1000393.pdf moved from folder /Volumes/Folder/Invoices/Invoice Staging to folder /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed.
2015-12-29 11:50:51.520 hazelworker[1818] ###main load address: 0x10a9d7000
2015-12-29 11:50:51.521 hazelworker[1818] ###Noodle load address: 0x10aae7000
2015-12-29 11:50:51.521 hazelworker[1818] ###CK load address: 0x10aaab000
2015-12-29 11:50:51.538 hazelworker[1818] Processing folder To Be Emailed
2015-12-29 11:50:52.649 hazelworker[1817] Done processing folder Invoice Staging
2015-12-29 11:50:53.682 hazelworker[1818] Client—2015-12-29-2015-INV-1000393.pdf: Rule Sample (Client) matched.
2015-12-29 11:50:53.682 hazelworker[1818] [File Event] File renamed: /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed/Client—2015-12-29-2015-INV-1000393.pdf renamed to /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed/Client—2015-12-29-2015-INV-1000393—client@example.com.pdf.
2015-12-29 11:50:53.714 hazelworker[1819] ###main load address: 0x10f503000
2015-12-29 11:50:53.715 hazelworker[1819] ###Noodle load address: 0x10f618000
2015-12-29 11:50:53.715 hazelworker[1819] ###CK load address: 0x10f5da000
2015-12-29 11:50:53.747 hazelworker[1819] Processing folder Invoice Staging
2015-12-29 11:50:54.110 hazelworker[1818] [File Event] File moved: Client—2015-12-29-2015-INV-1000393—client@example.com.pdf moved from folder /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed to folder /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed/Sent.
2015-12-29 11:50:55.154 hazelworker[1821] ###main load address: 0x100f82000
2015-12-29 11:50:55.155 hazelworker[1821] ###Noodle load address: 0x101096000
2015-12-29 11:50:55.155 hazelworker[1821] ###CK load address: 0x101058000
2015-12-29 11:50:55.175 hazelworker[1821] Processing folder Sent
2015-12-29 11:50:55.847 hazelworker[1819] File To Be Emailed is busy. Skipping for now.
2015-12-29 11:50:57.276 hazelworker[1821] Client—2015-12-29-2015-INV-1000393—client@example.com.pdf: Rule Sort into Subfolders by Month matched.
2015-12-29 11:50:57.277 hazelworker[1821] [File Event] File moved into subfolder: /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed/Sent/2015-12(Dec)/Client—2015-12-29-2015-INV-1000393—client@example.com.pdf sorted from folder /Volumes/Folder/Invoices/Invoice Staging/To Be Emailed/Sent to subfolder 2015-12(Dec).
我尝试在脚本和Hazel例程中的各个位置添加各种延迟;到目前为止,没有任何延迟(到目前为止最多一分钟)和看似没有延迟放置成功地使脚本附加文件。
简而言之,一切都按预期工作,但生成的电子邮件没有附件。我不确定在这一点上要尝试什么。任何建议都会受到欢迎。