Script No Longer Attaching File

I am currently using a script to attach a file in a monitored folder to an email and then send that email (or at least compose it and leave it open). While attempting to update the script to pull the addressee and email address from the file name, it would appear that I somehow broke the script and it is no longer attaching the file as it once did. I cannot seem to figure out where in the script the error lies. Here is the script I am using:
- Code: Select all
on hazelProcessFile(theFile)
set theAttachment1 to (POSIX path of theFile)
-- remove path from FileName
set text item delimiters to ":"
set FileName to last text item of (theFile as text)
-- remove the extension (last item when separated by ".")
set AppleScript's text item delimiters to "."
set SansExtension to every text item of FileName
set last text item of SansExtension to ""
set FileName to SansExtension as text
-- parse the name with the "—"
set AppleScript's text item delimiters to "—"
set clientName to first text item of FileName
set clientEmail to last text item of FileName
tell application "Airmail 2"
activate
set theMessage to make new outgoing message with properties {subject:"New Invoice", content:"Please find attached, infra, the current month's invoice."}
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