Monday, December 18, 2017

#26 2017-02-17 11:14:10 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

A part of the problem will be solved, the one forbidding to save the attachment without using the TIP.
At this time, the  problem related to the rule which doesn't pass the correct list continue to strike and I'm afraid that it will strike for long.


Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 17 février 2017 17:13:41

Offline

 

#27 2017-04-14 03:06:49 pm

mvasilakis
Member
Registered: 2014-10-28
Posts: 6

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

Hi,
I've tried implementing the solutions in this thread but can't seem to make this work. Admittedly I don't really understand applesctipt. I've tried inserting the tip to my script but no joy. It seems as though no matter what I do applecript will not recognize that an attachment exists. (I tried inserting a say statement before the "if theMessage's mail attachments is not {} then" line but it never triggers. This is a script that I found here years ago and keep adjusting slightly with each release when it stops working.

I get an email every day with an attachment titled OPIS_Pricing.csv. I need to save that in my downloads directory and kick off a script. I wish apple would simply include a damn rule for saving attachments and save me this recurring headache. /rant

Any help would be much appreciated.


Applescript:


using terms from application "Mail"
   on perform mail action with messages theMessages --for rule theRule
       -- Only use hardcoded path! DO NOT USE choose folder. It will crash Mail if you do
       
       -- Script modified for 10.8 on 09/12/13 MV
       -- as of Mac OS X 10.8 Mail.app applescripts can only save to the downloads directory
       -- the shell script below moves the file from downloads to its proper place for processing
       set theOutputFolder to ("/Users/me/Downloads/") as rich text -- replace quoted text with your desired path
       set theNextDelivery to "OPIS_Pricing.csv"
       tell application "Mail"
           repeat with theMessage in theMessages
               if theMessage's mail attachments is not {} then
                   repeat with theAttachment in theMessage's mail attachments
                       set theFileName to theOutputFolder & theNextDelivery
                       try
                           save theAttachment in theFileName
                       on error errnum
                       end try
                   end repeat
               end if
           end repeat
       end tell
       do shell script "/Users/me/Documents/Scripts/CurrentFuelCost/CurrentFuelCostScript_OPIS.sh"
   end perform mail action with messages
end using terms from

Offline

 

#28 2017-04-15 05:24:15 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

It seems that you are facing what I wrote in message #26:
A part of the problem will be solved (is solved under 10.12.4), the one forbidding to save the attachment without using the TIP.
At this time, the  problem related to the rule which doesn't pass the correct list continue to strike and I'm afraid that it will strike for long.


Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) samedi 15 avril 2017 12:24:10

Offline

 

#29 2017-04-15 06:40:23 am

mvasilakis
Member
Registered: 2014-10-28
Posts: 6

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

I cobbled together a temporary workaround in this find command

Applescript:

/usr/bin/find "/Users/me/Library/Mail/V4/" -type f -name "opis_racks_6to6.csv"| sed 's/.*/"&"/' | xargs ls -lTU |sort -k 9,9n -k 6,6M -k 7,7n | awk '{ print $10,$11 }' |tail -1 | xargs -I{} cp "{}" /tmp/opis_racks_6to6.csv

The only weird thing is that it doesn't seem to find the attachment right away. The email comes in at 7:07ish every day. Sometimes when I run the file at 8 it works flawlessly. Other days I am forced to re-run it the next morning. The timestamp on the file in the /Mail/V4/... directory indicates it wasn't created till 10 PM

Now I have a LaunchDaemon set to make sure mail is running at 6PM so it never misses the email. The timestamp on the email is 7:07 PM. The timestamp on the opis_racks_6to6.csv file is 22:12. Can someone explain this behavior to me? I'd like to run the script at 8PM the latest. Currently I'm forced to run it at 5AM just to be certain the the correct file actually exists.

Last edited by mvasilakis (2017-04-15 06:56:56 am)

Offline

 

#30 2017-10-11 01:22:38 am

davidhmorgan
Member
From:: Sydney
Registered: 2014-08-20
Posts: 60

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

NickeZ28, could you let us know how you created the Automator work-around for this?

I have set up an Automator workflow that gets the selected messages in Mail and saves their attachments to the documents folder. The limitation is that the emails must first be selected in Mail. Is it possible for a Mail rule AppleScript to pass the received emails as input to the Automator workflow?

Last edited by davidhmorgan (2017-10-11 01:24:58 am)


Filed under: mail, Automator

Offline

 

#31 2017-10-11 06:44:15 pm

davidhmorgan
Member
From:: Sydney
Registered: 2014-08-20
Posts: 60

Re: Mail.app save attachment - stopped working after Sierra 10.12.2 update

Hi all,
I managed to work out how to do this by actually reading what has been discussed above. Yvan's TIP did the trick for me (thanks Yvan). The problem was that Mail was refusing to save the attachments due to some kind of permissions issue. The following code sorted it out:

Applescript:


set savePath to attachmentsFolder & originalName
close access (open for access savePath)
set savePath to savePath as «class furl»
save theAttachment in savePath

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)