Previous 1 2 3 4 Next 52 Replies Latest reply: Feb 3, 2014 6:09 AM by LogicProLetsGo Go to original post
  • 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 Level 1 Level 1 (0 points)

    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

  • Screaming.Pict Level 1 Level 1 (0 points)

    pfly- your script looks OK. One thing that I did notice was that finder paths in applescript usually expect ":' instead of "/" in folder names.

     

    I wonder if that might spark the difference between running it manually (where you're not sandboxed) and running it automatically.

     

    Try changing the path to;

     

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


    and let us know what happens.

  • 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. 

  • Screaming.Pict Level 1 Level 1 (0 points)

    OK so the next step is to get some diagnostics going.

     

    Put a bunch of lines in to display your variables at each step with 'display dialog'

     

    e.g. before

     

    set file_path to (folder_path)

     

    Put in a line;

     

    display dialog "File path: " & file_path

     

    do the same before & after lots of statements and you should be able to see whether your variables are correct and if the relevant parts of the script are being run.

     

    P.S. you could also try just changing the save folder to your downloads folder in case there's a permissions issue somewhere.

  • 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


  • Screaming.Pict Level 1 Level 1 (0 points)

    Hmm.. I'm none the wiser from that.

     

    One thing to try- I noticed that you were setting the variable folder_path using subject of theMessage.

     

    Could you try taking that out and see if anything changes- just in case applescript isn't a fan of compounding the statement like that? In the script I use I set that in a variable and then use the variable instead of putting it directly into the statement.

  • 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


  • Screaming.Pict Level 1 Level 1 (0 points)

    pfly,

     

    Below is my exact script, saved in ~/Library/Application Scripts/com.apple.mail/SaveAttachments.scpt

     

    All that you need to do is change the location. I would suggest initially just taking the '3 month holding folder' off so that it saves to 'Downloads' as that's the location that Mail.app is happiest saving to.

     

    using terms from application "Mail"

              on perform mail action with messages theselectedMessages

      -- get the home folder

                        set sandboxedhomeFolder to (path to home folder)

      -- strip out the stupid sandboxed rubbish in the folder name

                        set homeFolder to (do shell script "echo " & sandboxedhomeFolder & " | sed 's/Librar.*//'")

      -- add on the desired attachments folder (must be somewhere Mail can write to)

                        set attachmentsFolder to homeFolder & "Downloads:3 Month Holding Folder"

                        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

      -- name the file with the sender's name as well as the attachment name

                                                      set savePath to attachmentsFolder & ":" & senderName & "-" & originalName

                                                      try

      -- Save the attachment

      save theAttachment in savePath

                                                      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)

    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

  • Screaming.Pict Level 1 Level 1 (0 points)

    Weird.

     

    OK- you could try running a repair permissions on your disc.

     

    (Open Disk Utility, select your boot disc and click 'repair permissions').