Skip navigation

Applescript to save mail attachments failing in Mountain Lion

16643 Views 52 Replies Latest reply: Feb 3, 2014 6:09 AM by LogicProLetsGo RSS
  • jbublik Level 1 Level 1 (0 points)

    I see, so the only difference with the old  (snow leopard) version is the

     

    --set attachmentsFolder to ((path to home folder as text) & "Documents:Symbolic") as text was my old one

              set attachmentsFolder to "Macintosh HD:Users:jbublik:Downloads:Symbolic:" is my new one.

    I tried - it still doesn't work. Why my scripts won't work? I am really puzzled

  • jbublik Level 1 Level 1 (0 points)

    Never mind. I copied the script above and got it working - downloading to "Downloads" folder Not sure why the script would work on Mountain Lion, when it worked on Snow leopard. I understand that the priviledges were changed -rw, but why the syntax was changed? beyond me.

  • pfly Calculating status...

    Sorry, I'm a real simple user when it comes to scripts.  Can you please post the whole script with the modification you made included?  I tried subbing it the folder path part and making the destination "downloads" and didn't get results.

  • pfly Level 1 Level 1 (0 points)

    I've gotten a little further.  Here's the script I'm using, I added a subject to the file name, but otherwise I think it's pretty close to Screaming.Pict's original.  Where I'm having problems is on the execution of the rule.  Annoying thing is it works if I select apply rule, but it doesn't work if I send a test message to trigger the rule. 

     

    using terms from application "Mail"

              on perform mail action with messages theselectedMessages for rule theRule

     

                        tell application "Mail"

                                  repeat with theMessage in theselectedMessages

      -- get the sender's name

                                            set senderName to extract name from theMessage's sender

                                            repeat with theAttachment in theMessage's mail attachments

                                                      set originalName to name of theAttachment

     

                                                      set folder_path to "/Users/pfly/Downloads/Dropbox/Chemistry/" & senderName & "-" & subject of theMessage & "-" & originalName

     

                                                      set file_path to (folder_path)

     

                                                      try

     

      save theAttachment in file_path

                                                      end try

                                            end repeat

                                  end repeat

                        end tell

              end perform mail action with messages

    end using terms from


  • pfly Level 1 Level 1 (0 points)

    And here's screenshots (hopefully) showing that I'm not an idiot and have my rule set up right and the script is in the right place...

     

    Screen Shot 2012-08-06 at 12.18.54 AM.png

     

    Screen Shot 2012-08-06 at 12.20.57 AM.png

    MacBook Pro (15-inch 2.4/2.2 GHz), OS X Mountain Lion
  • pfly Level 1 Level 1 (0 points)

    Switched the path to

     

    "Users:pfly:Downloads:Dropbox:Chemistry:"

     

    and it didn't work manually or automatically.  I added in my MacHD before the first colon and then it worked, but still only manually. This is what the path is now... "MacHD:Users:pfly:Downloads:Dropbox:Chemistry:"

     

    I'm not sure why I moved to the /.  At some point it seemed to help, but I'll leave it as the : since that seems more official. 

     

    I did a search on scripts working manually but not automatically and found some clues, but no answers.  The frustrating thing is that it seems that the script is ok, but Mail isn't using it automatically.  One thing I found was to save the script as a bundle, but that doesn't seem to work anymore.

     

    A test I just ran was to add a sound in the rule before the script and a color change after the script.  Both happen automatically, so it doesn't seem like the script is causing the rule to stop working.

     

    Thanks for your interest/help. 

  • pfly Level 1 Level 1 (0 points)

    Tried the diagonstics, great tip. I just did it as shown below to make it a little quicker.  It stops at 2, so there seems to be a problem with

      set senderName to extract name from theMessage's sender.

     

    When I comment out that line, it then stops at 3. 

     

    When I manually run the script, it goes all the way up to 7 and successfully finishes the script. 

     

    P.S. The script doesn't seem to even get to the save path, but I tried chaning it to just downloads just to see and that didn't work. 

     

     

     

     

     

    using terms from application "Mail"

              on perform mail action with messages theselectedMessages for rule theRule

     

      display dialog "1"

     

     

                        tell application "Mail"

                                  repeat with theMessage in theselectedMessages

      -- get the sender's name

     

      display dialog "2"

     

                                            set senderName to extract name from theMessage's sender

     

      display dialog "3"

     

                                            repeat with theAttachment in theMessage's mail attachments

                                                      set originalName to name of theAttachment

     

      display dialog "4"

     

                                                      set folder_path to "MacHD:Users:pmfleisch:Downloads:Dropbox:Chemistry:" & senderName & "-" & subject of theMessage & "-" & originalName

     

     

      display dialog "5"

     

                                                      set file_path to (folder_path)

     

      display dialog "6"

     

                                                      try

      -- Save the attachment

      -- ** the code seems to get this far and then doesn't actually save the

      -- ** file in the location indicated

     

      display dialog "7"

     

      save theAttachment in file_path

                                                      end try

                                            end repeat

                                  end repeat

                        end tell

              end perform mail action with messages

    end using terms from


  • pfly Level 1 Level 1 (0 points)

    I took out the subject variable and it didn't make a difference.

     

    What I don't understand is why it works manually but not automatically.  Doesn't it seem like the kind of thing that should either work or not work?

     

    Can you resend your exact script so I can try that out?  I think all I'd have to change is the location, right?

  • pfly Level 1 Level 1 (0 points)

    Also, I tried running my script on my other computer that is still running lion, didn't work there either.  Stopped at 2.

     

     

                                                                set senderName to extract name from theMessage's sender


  • pfly Level 1 Level 1 (0 points)

    Screaming.Pict,

     

    Just tried it and it didn't work.  Did the diagnostic and it's getting stuck on the line below just like mine is.  Is there another way to do this part?  Is there any reason it would work for you, but not for me?  A permission somewhere?

     

                                            set senderName to extract name from theMessage's sender


    I did play around and if I take that line out as well as

     

                                                           repeat with theMessage in theselectedMessages

     

    then the next place it gets stuck is

     

                            

                                                      set originalName to name of theAttachment

Actions

More Like This

  • Retrieving data ...

Bookmarked By (4)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.