Delete an attachment

This seems like a simple task but I haven’t been able to find an example anywhere. All attachment examples seem to be for saving an attachment. I want to delete one. This is for on Leopard.

I’ve got the code working to pull messages and to pull attachments for messages. I’ve got the code working to select the exact attachments I want to delete but can’t figure out how to actually delete the attachment.

This doesn’t work:

tell theMessage
delete mail attachment (id of theAttachment)
end tell

neither does:

delete mail attachment theAttachment


delete theAttachment


Is this even possible?



Hi Ted,

welcome to MacScripter :slight_smile:

It’s not possible to delete attachments with Mail’s dictionary.
The only way is to call the menu item of the Message Menu with GUI scripting

Well, not the answer I was looking for but thanks for the information. If it’s not possible to delete a specific attachment, is it possible to delete all of them? If that’s the menu item you were talking about, how do I select the message with Applescript so the menu will apply to the message?

next problem:

the property selection in is read only, you can’t select messages easily with an AppleScript command.
maybe it’s also possible with UI scripting, but I’ve never tried to do that