1 2 3 4 5 Previous Next 68 Replies Latest reply: Jul 30, 2013 2:30 AM by Nick Williams1 Go to original post
  • 15. Re: Applescript on Mountain Lion not working
    Jacknumpty Level 1 Level 1 (0 points)
  • 16. Re: Applescript on Mountain Lion not working
    KasparV Level 1 Level 1 (0 points)

    Heey, I ran in to the same issue as you with SickBeard, unable to use the Apple Script Editor (or Automator for that matter) to make SickBeard bootable without Terminal, and I solved it by making a command in Terminal:

     

     

    - press CMD+SHIFT (to make plain text in Text Editor)

    - copy this code:

    #! /bin/sh

    python /Applications/Sick-Beard/sickbeard.py -d

     

    - NOTE: /Applications/Sick-Beard/ is where my SickBeard is located, if you have another directory, change that

     

    - Save file as "runsickbeard.command"  and save it to user directory

    - In terminal type: chmod 755 sickbeard.command

    - now your .command should work and you can add it to your login items if you want it at startup

     

    Goodluck!

  • 17. Re: Applescript on Mountain Lion not working
    Niko Nyman Level 2 Level 2 (270 points)

    I got so far today while debugging Mail rules under Mountain Lion:

     

    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. Seems that when Applescript gets the list of messages, the messages are no longer in the Incoming POP Messages mailbox, but in the Inbox. Applescript throws an invalid index error, because Applescript can't access item 1 of an empty mailbox.

     

    But, when a Mail rule fires on an IMAP account, the rule gets passed a correct list of messages in the Inbox.

     

    This probably explains why some people say the rules work sporadically.

  • 18. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    I may have a workaround.

    Instead of:

    using terms from application "Mail"

              on perform mail action with messages theMessages

                        tell application "Mail"

     

    I used:

    tell application "Mail"

              repeat with theMessage in (every message of inbox)

     

    So, instead of running the Applescript on incoming messages, I will run the Applescript on the inbox whenever an incoming message is received.

  • 19. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

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

  • 20. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    This now works for me as a mail rule:

     

    tell application "Mail"

              repeat with theMessage in (every message of inbox)

                        set theSender to (sender of theMessage)

                        if theSender contains "Canadian-Pharmacy" then

                                  try

                                            set the read status of theMessage to true

                                            set the junk mail status of theMessage to true

                                            set theAccount to (account of mailbox of theMessage)

                                            set mailbox of theMessage to (mailbox "Junk" of theAccount)

                                  end try

                        end if

              end repeat

    end tell

     

    -- FYI, this is a shortened version of my script.


     

    ======================

     

    The old script that worked with Lion, but stopped working with ML was:

    using terms from application "Mail"

              on perform mail action with messages theMessages

                        tell application "Mail"

                                  repeat with theMessage in theMessages

                                            set theSender to (sender of theMessage)

                                            if theSender contains "Canadian-Pharmacy" then

                                                      try

                                                                set the read status of theMessage to true

                                                                set the junk mail status of theMessage to true

                                                                set theAccount to (account of mailbox of theMessage)

                                                                set mailbox of theMessage to (mailbox "Junk" of theAccount)

                                                      end try

                                            end if

                                  end repeat

                        end tell

              end perform mail action with messages

    end using terms from

     

    ======================

     

    So, removing the following:

    using terms from application "Mail"

              on perform mail action with messages theMessages

                        tell application "Mail"

                                  repeat with theMessage in theMessages

    and using

    tell application "Mail"

              repeat with theMessage in (every message of inbox)

     

    works for me

     

    Now, instead of running the Applescript on incoming messages, the Rule will run the Applescript on the inbox whenever an incoming message is received.

    Note that there must be code to move the message from from the inbox.

  • 21. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    Tony T1 wrote:

     

    Note that there must be code to move the message from from the inbox.

     

    ...or test if message read flag is false:

     

    if read status of theMessage is false then

        ...

    end if

  • 22. Re: Applescript on Mountain Lion not working
    HenriHoffmann Level 1 Level 1 (0 points)

    Hi,

     

    have the same problem, but no solution. I have linked the user home to an other volume in order to be able to use vSphere Snapshots. I assume this is the reason of this message. Same at you installation?

     

    Thanks

    Henri

     

    lrwxr-xr-x   1 root           admin   35 25 Jun 23:06 tshenri -> /Volumes/MacTS vLocal/Users/tshenri

     

    Oct 12 13:25:37 macts.sysconsult-office.de Mail[62878]: Failed execution of AppleScript: /Users/tshenri/Library/Application Scripts/com.apple.mail/Mail Rule - M

    ail to DevonThink.scpt

            Error Domain=NSCocoaErrorDomain Code=257 "The file “Mail Rule - Mail to DevonThink.scpt” couldn’t be opened because you don’t have permission to view it

    ." UserInfo=0x7faa5dd64e30 {NSURL=file://localhost/Users/tshenri/Library/Application%20Scripts/com.apple.m ail/Mail%20Rule%20-%20Mail%20to%20DevonThink.scpt, NSL

    ocalizedFailureReason=Script file is not in the application scripts folder.}

  • 23. Re: Applescript on Mountain Lion not working
    twtwtw Level 5 Level 5 (4,690 points)

    That's fine if it works, but it's no longer a Mail rule action.  You're just running ascript on your entire inbox every time a message arrives.

  • 24. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    twtwtw wrote:

     

    That's fine if it works, but it's no longer a Mail rule action.  You're just running ascript on your entire inbox every time a message arrives.

     

    Hence, why I called it a "workaround"

    If you have a solution to the problem, please let me know.

  • 25. Re: Applescript on Mountain Lion not working
    twtwtw Level 5 Level 5 (4,690 points)

    Well, I haven't bought Mountain Lion yet.  I needed to get a new computer, because my beloved 2006 model isn't supported.   But I can say this much.  The Mail rule itself works - the script is being called (otherwise your workaround wouldn't work) - so the problem is most likely in the script itself, not an issue with Mail.

     

    Two things to try, as diagnostics.  First, replace your code with the following:

     

    using terms from application "Mail"

              on perform mail action with messages theMessages

                        tell application "Finder"

      display dialog theMessages as string

                        end tell

              end perform mail action with messages

    end using terms from


    This will probably throw an error regardless, but it should tell you whether or not Mail is passing on the list of messages to the script.  If the messages are not being passed on, re-check your Mail rule to make sure it's not accidentally excluding all the messages you're interested in.

     

    FYI, I've used the Finder rather than Mail for the display just as a precaution. Mail scripts run on background threads, and I'm not certain whether applescript will send commands from one thread to another.

     

    Assuming that the messages are being passed in, then move on to the second diagnostic.  use the following code:

     

    using terms from application "Mail"

              on perform mail action with messages theMessages

                        try

                                  tell application "Mail"

                                            repeat with theMessage in theMessages

                                                      set theSender to (sender of theMessage)

                                                      if theSender contains "Canadian-Pharmacy" then

                                                                set the read status of theMessage to true

                                                                set the junk mail status of theMessage to true

                                                                set theAccount to (account of mailbox of theMessage)

                                                                set mailbox of theMessage to (mailbox "Junk" of theAccount)

                                                      end if

                                            end repeat

                                  end tell

                        on error errstr

                                  my diagnosticAlert(errstr)

                        end try

              end perform mail action with messages

    end using terms from

     

    on diagnosticAlert(errstr)

              tell application "Finder"

      activate

      display alert "Mail Error" message errstr

              end tell

    end diagnosticAlert

     

    that enclosing try block will catch any script errors and display them in the Finder.

     

    Do those and let me know what results you get.

  • 26. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    I already tried with simple scripts (also, the script worked with Lion, and also works currenlty with ⌥⌘L in ML)

    This is a bug (see:in response to Niko Nyman)

    Bug report filed (apple develpoment responded)  Should be fixid in a year or so   Till then, workarround will have to do.

  • 27. Re: Applescript on Mountain Lion not working
    twtwtw Level 5 Level 5 (4,690 points)

    It may be a bug, it may be a consequence of a security feature.  we won't be able to diagnose it until you run the above scripts and tell me the results.  I don't know what you've tried before, so I can't tell whether or not your tests were valid.

     

    No disrespect to your workaround - it's a great workaround - but let's not rest on your laurels.

  • 28. Re: Applescript on Mountain Lion not working
    Tony T1 Level 6 Level 6 (8,380 points)

    I tired the 1st script you posted (or a variation of it) before.  Tried it again, and nothing occurs.  Script is running (i.e. if I display dialog "Hello World"), but not theMessages.  Looks like "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."

  • 29. Re: Applescript on Mountain Lion not working
    Niko Nyman Level 2 Level 2 (270 points)

    If you want to target the received messages more carefully, you could use something like this:

     

    using terms from application "Mail"

         on perform mail action with messages ruleMessages

              set limitDate to current date

              set limitDate to limitDate - 1 * minutes

              -- Get only messages that are not in the inbox with a deleted flag, and which have been received in the last minute

              set newMessages to (messages in inbox) whose deleted status is false and date received > limitDate

     

              repeat with newMessage in newMessages

                   -- Do something with newMessage...

              end repeat

         end perform mail action with messages

    end using terms from

     

    You may need to change the limitDate to a few more minutes for a slower connection.