Applescript to delete Mail message [newbie]

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Applescript to delete Mail message [newbie] Thu Jul 03, 2008 4:12 am • by eN0ch
I believe there are some Applescripters on here? .. I'm trialling Hazel, and would like it to do the following for me:
• copy .emlx files from certain Mail.app folders (i.e. in -/Library/Mail) to a folder in -/Documents
• add text to Spotlight comments on the copies
• have Mail.app delete the original messages

The first two of these are working a treat, but I'm stuck on the last. I'm hoping for an applescript that could be triggered by the Hazel rule. I've managed a script that works independently of Hazel, but Hazel can't run it. here's the script I've created in my scripto-ignorance:
tell application "Mail"
    set theMessage to message 1 of mailbox "Archive"
    delete theMessage
end tell


Can someone help me edit to work with Hazel? Thanks.
Lance <º))><

iMac 24" 2021 M1 | macOS 14.4.1 | Hazel 5.2.1
eN0ch
 
Posts: 63
Joined: Tue Jul 01, 2008 7:41 pm
Location: Crookwell, NSW, Australia

Check the Help. There's a specific handler you have to use. Just plop your code into it.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Applescript to delete Mail message [newbie] Thu Jul 03, 2008 7:26 pm • by eN0ch
Thanks for that. I assume it's just a case of pasting "on hazelProcessFile(infile)" in at the top of my existing script, and pasting "end hazel_process_file" at the bottom? If so, I've done that.

I guess I'm now left with just one point of uncertainty (NB: I'm neither a general geek nor an AS geek.) I'm wondering whether my use of "message 1" in my script will correctly point to the same message that Hazel is currently acting on, or whether it might point to another one ... (in which case, might I end up deleting a message Hazel hasn't got to yet -- and hence never will get to!)

Any insights ... ?
Lance <º))><

iMac 24" 2021 M1 | macOS 14.4.1 | Hazel 5.2.1
eN0ch
 
Posts: 63
Joined: Tue Jul 01, 2008 7:41 pm
Location: Crookwell, NSW, Australia

I haven't played with using AppleScript with Mail much so I'm not sure what message is being referred to nor do I know a good way to correlate the file (which would be the emlx file, I assume) to a message that Mail would recognize in AppleScript. I'd exercise caution here and maybe do something non-destructive to the message (like coloring or flagging it) until you can get the logic right, if it's possible at all.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support