Hazel Fails to Attach File to Email (El Capitan)

﹥>﹥吖頭↗ 提交于 2019-12-13 07:19:01

问题


I currently have a set of Hazel routines that all use the same AppleScript, included infra. The routine does the following:

  1. Monitors Folder and examines PDFs placed into Folder for certain strings.

If a matching string is found:

  1. Renames the matched file using the following scheme: name—email—extension (i.e., it inserts an email address, which is predefined in the Hazel routine).

  2. Runs the AppleScript (again, infra).

  3. Moves the matched file to an archive folder.

Here is the 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

end hazelProcessFile

This script parses the file and generates the email using the information contained in the file name. Everything works as expected, except the file is not actually attached to the email. I had a much simpler version of this script working, but everything was hardcoded into the script and it couldn't be used for anything other than the single client for whom it was designed (e.g., it actually had the client's name and email coded into the script instead of pulling them from the file).

Here is the result in Console when the Hazel routine is triggered:

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).

I've tried adding various delays in various spots in the script and in the Hazel routine; thus far, no amount of delay (up to one minute so far) and seemingly no delay placement has succeeded in getting the script to attach the file.

In short, everything works as expected except the generated email does not have an attachment. I am uncertain what to try at this point. Any recommendations would be welcome.

来源:https://stackoverflow.com/questions/34518158/hazel-fails-to-attach-file-to-email-el-capitan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!