Hi,
I managed to create a script a few weeks ago for deleting a message I’ve just sent if I click a certain button in a dialog. It works very well except for one thing. I use the script in conjunction with a set of rules in Hazel for periodically copying .emlx files from ~Library/Mail/myAccount/Sent Messages.mbox/Messages to a folder in ~/Documents. The purpose of the script is to trash sent messages I don’t want to keep so they don’t then get copied to the other folder.
The problem I’ve discovered is that, even after my script has run and the message has disappeared from the “Sent” mailbox (and now appears in the “Trash” mailbox), the .emlx file is still in the “…/Sent Messages.mbox/Messages” folder (with a duplicate in the “…/Deleted Messages/…” folder; the duplicate’s filename is one number after the original’s filename). If the original .emlx stays in the “Sent” box, then in due course the Hazel rule will run and copy this unwanted file to Documents.
After a bit of investigation I’ve discovered that the original .emlx file disappears from “Sent” the moment I select “Trash” in the left panel of the Mail.app viewer window. So I’m assuming what I need is an add-on to my existing script, that will do something under the hood equivalent to selecting the “Trash” box for the relevant account. I’m hoping this could be scripted such that Mail.app wouldn’t have to become the front application; but I guess I could live with the latter if necessary.
As always when I try to figure out an applescript I get to a point where no amount of googling and experimenting is going to produce what I want. That point has again been reached, so I’m turning to you guys for hope and consolation …
Here’s my current script (including the Hazel handlers - first & last lines):
on hazelProcessFile(infile)
tell application "Mail"
activate
set theMessage to message 1 of mailbox "Sent Messages" of account "myAccount" of application "Mail"
set theSubject to subject of theMessage
display dialog theSubject & "... Save copy?" buttons {"No", "Yes"} default button 1
if (button returned of the result) = "No" then
set mailbox of theMessage to mailbox "Deleted Messages" of account "myAccount" of application "Mail"
end if
end tell
end hazelProcessFile
TIA …
Model: macbook2.16
AppleScript: 2.2
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.12) Gecko/20080206 Camino/1.5.5
Operating System: Mac OS X (10.5)