Tuesday, June 27, 2017

#1 2017-06-12 11:57:26 pm

Registered: 2017-06-12
Posts: 1

Whether or not an Open Mail Composition has an Attachment

I've been searching around for a resolution to this issue for a few weeks now without being able to figure out a good answer:

Given an open Compose Mail window in Mail.app (Sierra), is it possible to run a script to determine whether or not that mail has an Attachment?

In an ideal proof of concept:

- Open Mail.app
- File->New Message
- Add an Attachment to the message
- Run a script, and display an alert if the message has an attachment. Do nothing if this script is run and the message has no attachment.

Thanks for any help or final answer to this question!


Operating System: Mac OS X (10.10)

Filed under: mail, Attachment, new



#2 2017-06-13 08:23:18 pm

From: BFE, Massachusetts
Registered: 2013-01-12
Posts: 185

Re: Whether or not an Open Mail Composition has an Attachment

This is working for me:


-- Assumes the message is in front and relies on it being the most recent message with the same title in the Drafts folder.

tell application "Mail"
   set windowName to the name of the first window
   repeat with aMessage in the messages of drafts mailbox
       if the subject of aMessage is windowName then
           set theMessage to contents of aMessage
           exit repeat
       end if
   end repeat
   set foundAttachments to every mail attachment of theMessage
   if (count of foundAttachments) > 0 then
       set attachmentNames to ""
       repeat with anAttachment in foundAttachments
           set attachmentNames to attachmentNames & the name of anAttachment & return
       end repeat
       set dialogText to "The following files were attached to the currently open draft message \"" & windowName & "\":" & return & attachmentNames
       display dialog dialogText
   end if
end tell

Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb



Board footer

Powered by FluxBB

[ Generated in 0.066 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)