MacNN Forums (
-   Developer Center (
-   -   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:


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"
                        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
                                                                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 01:02 PM.

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

Content Relevant URLs by vBSEO 3.3.2