Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScripting Mail

AppleScripting Mail
Thread Tools
bojangles
Senior User
Join Date: May 2000
Location: Lafayette, IN, USA
Status: Offline
Reply With Quote
Mar 4, 2013, 03:07 PM
 
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! :-)
“The trouble with quotes on the Internet is that you can never tell if they’re attributed to the right person.”
—Abraham Lincoln
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:59 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,