Hello
Very new to any AppleScripting and need some easy help.
How can I change my Applescript Example below to have the Filename show up in the Subject line of this email script? I am using this script with the software Hazel.
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"Hello from your Mac!", content:"You got a new file in your Downloads folder", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"EMAILADDRESS@EMAIL.COM"}
send
end tell
Thanks in advance for any help.
Your script does not compile. It has two tell commands, but only one end tell. It’s advisable to work out a new script in the Script Editor, so you know it will compile. Hazel only posts cryptic messages in its log when scripts do not run as expected.
That said, on to your question. I assume you have read the relevant paragraphs in Hazel’s Help, specifically Writing AppleScript for Hazel. It tells us that Hazel passes an alias to any script it runs. The file’s name is easily obtained from this alias:
-- 'theFile' contains an alias
set AppleScript's text item delimiters to ":"
set theName to last text item of (theFile as text)-- turning alias into text
set AppleScript's text item delimiters to ""
Your script becomes:
set AppleScript's text item delimiters to ":"
set theName to last text item of (theFile as text)
set AppleScript's text item delimiters to ""
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theName, content:"You got a new file in your Downloads folder", visible:true}
tell theNewMessage
make new to recipient at end of to recipients with properties {address:"EMAILADDRESS@EMAIL.COM"}
send
end tell
end tell
The subject will now be set to the file name.
Brilliant!
Thank you so much, for taking the time to resolve this for me.
Cheers!