Hazel, applescript and email attachments [Mac]

For my day job, I regularly need to send a daily dashboard report  (I call these "Daily Awareness Reports") as an attachment to emails.

Having generated a pdf of the report I use Hazel and AppleScript to attach the pdf to an email and send it. Furthermore, I send myself an email with the report to check that it has been completed correctly and maintain it for my records. 

I previously tried an Automator workflow, but the "Get Selected Finder Items" command would include previously selected files and attach them to the email as well. Needless to say, this could look a little unprofessional....

So here is my workflow. 

I created a Dropbox folder for Daily Awareness Reports, which is where I save these reports when they are completed.

Next, I get Hazel to watch this folder.

The Hazel rule watches for pdf documents AND file names containing "Daily Awareness" (the file name I use but use what works for you).

Once it notices a file that fulfils these conditions it runs two scripts.

The first sends the report to the users.

set theAttachment1 to (POSIX path of theFile)
set subject_ to "Daily Report"
set the_content to "Find attached Daily Report"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
tell newMessage

set visible to false
set sender to "my1@mac.com"
make new to recipient at end of to recipients with properties {address:"their@mac.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph

(* change save to send to send*)
send --<<<<---------------- change save to send to send or send to save to save to drafts
(* change save to send to send*)
end tell
end tell

The second scripts lets me know it is all done. 

set theAttachment1 to (POSIX path of theFile)
set subject_ to "Daily Report"
set the_content to "Daily Report Sent"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
tell newMessage

set visible to false
set sender to "my1@mac.com"
make new to recipient at end of to recipients with properties {address:"my1@mac.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph

(* change save to send to send*)
send --<<<<---------------- change save to send to send or send to save to save to drafts
(* change save to send to send*)
end tell
end tell

The last step in the rule deletes the document. This is very important to ensure that it doesn't keep on sending emails. Needless to say this could also be a little embarrassing....

This code is based on a post on Stackoverflow done by markhunte.