7 Replies Latest reply: Sep 10, 2012 12:44 PM by Jacknumpty
Jacknumpty Level 1 Level 1 (0 points)

Hi after upgrading to Mountain Lion (ML) the applescript that I use to reply to certain emails has stoped working on incoming emails. I have the script in the "new" correct folder. The funny thing is that the script works when you "apply rules" from the messages dropdown menu.


OS X Mountain Lion (10.8)
  • 1. Re: Applescript stopped working after Mountain Lion upgrade
    Jacknumpty Level 1 Level 1 (0 points)

    This is the script:

     

    using terms from application "Mail"

              on perform mail action with messages theMessages for rule theRule

      --tell application "Mail"

                        repeat with eachMessage in theMessages

      --set theContent to content of eachMessage

                                  set emailFrom to extract address from sender of eachMessage

                                  try

      --set AppleScript's text item delimiters to {"(", ")"}

      --set contentParts to (every text item in theContent) as list

      --set AppleScript's text item delimiters to ""

      --set emailOnly to item 2 of contentParts

      --set recipientAddress to emailOnly

                                            set recipientAddress to emailFrom

                                            set theSubject to "Text for subject"

                                            set theSignature to signature "One"

                                            set theSendContent to " "

                                            set theSender to "dave@gmail.com"

                                            set theMessage to make new outgoing message with properties {subject:theSubject, content:theSendContent, sender:theSender, visible:true}

                                            tell theMessage

      make new to recipient with properties {address:recipientAddress}

                                                      set message signature to theSignature

                                                      send

                                            end tell

                                  end try

                        end repeat

      --end tell

              end perform mail action with messages

    end using terms from


  • 2. Re: Applescript stopped working after Mountain Lion upgrade
    Niko Nyman Level 2 Level 2 (270 points)

    Seems like Applescript rules in Mail 10.8 are not working for messages retrieved from POP accounts.

     

    If a Mail rule fires on a POP account, the rule gets passed a list of messages contained in a special "Incoming POP Messages" mailbox, but when the Applescript tries to access the messages, the Incoming POP Messages mailbox is empty.

  • 3. Re: Applescript stopped working after Mountain Lion upgrade
    Jacknumpty Level 1 Level 1 (0 points)

    If this is true I hope Apple will fix this. Sounds quite strange that It worked in 10.7 Would be nice to hear somthing official from apple on this.

  • 4. Re: Applescript stopped working after Mountain Lion upgrade
    Tony T1 Level 6 Level 6 (8,380 points)

    I may have a workaround until (if) Apple fixes this bug.

    See: https://discussions.apple.com/message/19514671

     

    You will need to add a line to your code to move the messages out of the inbox after processing.

  • 5. Re: Applescript stopped working after Mountain Lion upgrade
    Jacknumpty Level 1 Level 1 (0 points)

    Thankyou Tony, we have used your workaround and it works great!  We have changed our rule to flag the emails and move them to a new "Sales" folder, then run the applescript.  The applescript looks at all flagged emails in the Sales folder, processes them, then unflags them.  Here is the script:

     

    using terms from application "Mail"

                   tell application "Mail"

                                  repeat with eachMessage in (every message of mailbox "Sales")

                                                 set flagIndex to (flag index of eachMessage)

                                                  if flagIndex is not -1 then

                                                                try

                                                                               set the flag index of eachMessage to -1

                                -- Do processing here

                          end try

                                                 end if

                                  end repeat

           end tell

    end using terms from

  • 6. Re: Applescript stopped working after Mountain Lion upgrade
    Tony T1 Level 6 Level 6 (8,380 points)

    Flagging the email is a good way to prevent the script to process the email more than once.

    Another test to consider is if the read flag is false:

    if read status of theMessage is false then

        ...

    end if

  • 7. Re: Applescript stopped working after Mountain Lion upgrade
    Jacknumpty Level 1 Level 1 (0 points)

    Thanks Tony, wrote a bit more about it here if you or anybody is interested: http://bee-software.net/blog/mail-rules-applescript-not-working-after-upgrade-to -mountain-lion/