MacNN Forums (http://forums.macnn.com/)
-   Developer Center (http://forums.macnn.com/developer-center/)
-   -   AppleScripting Mail (http://forums.macnn.com/79/developer-center/498582/applescripting-mail/)

 
bojangles Mar 4, 2013 02:07 PM
AppleScripting Mail
Hey, everyone. I’m stuck with an intensely annoying issue: I have an AppleScript that’s attached to a Mail rule. The intended behavior is for the rule to check the message for a csv-formatted attachment and, if one exists, save it and run some other processes on it. Unfortunately, I’m getting stymied right at the beginning: it only works if I right-click a message and select “Apply Rules.” I suspect the issue is that when the rule runs, the message isn’t actually selected, so the script isn’t able to process it.

Here’s the relevant portion of the script:

Code:

using terms from application "Mail"
        on perform mail action with messages theMessages for rule theRule
               
                -- Get incoming messages that match the rule
                tell application "Mail"
                        activate
                        repeat with theMessage in theMessages
                                -- Save the attachment
                                repeat with theAttachment in theMessage's mail attachments
                                        set filename to name of theAttachment as string
                                        if (characters -1 thru -3 of filename) as string = "csv" then
                                                set asPath to (asFolder & ":" & filename) as string
                                                        try
                                                                save theAttachment in file asPath
                                                        end try

--remainder of code omitted for brevity
--all “end”s are in place

Again, I believe the problem is that when the message comes in, Mail doesn’t select it. Since there’s no selection, the script is unable to get its attachment. How do I tell Mail to select the message when it comes in, so it can grab the attachment if needed?

Thanks so much! :-)
 
All times are GMT -4. The time now is 03:51 AM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2016, vBulletin Solutions, Inc.


Content Relevant URLs by vBSEO 3.3.2