Giter Club home page Giter Club logo

Comments (17)

jneug avatar jneug commented on July 19, 2024 2

I just comited a new version of the script that should save all attachments for an email.

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

Try this version and let me know if it works:

(*
name:           Save attachments
apps:            Airmail 3
description:    Use as a script in Airmail rules to save attachments to the selected folder.
parameters:
    DOWNLOADS:      Folder to save attachments to
compile:        false
*)
property DOWNLOADS : "~/Downloads"

on processMessage(theMessage)
	try
		tell application "Airmail 3"
			repeat with theAttach in mail attachment of theMessage
				--set theAttach to filename of first mail attachment of theMessage
				set thePDF to quoted form of POSIX path of filename of theAttach
				do shell script "cp " & thePDF & " " & DOWNLOADS
			end repeat
		end tell
	end try
end processMessage

from osx-script-stuff.

crjstobal avatar crjstobal commented on July 19, 2024

Didn't work for me :(

What I've done is create several scripts changing

set theAttach to filename of first mail attachment of theMessage

For "second", "third" and so, and then execute all of them, but I think it has to be a better solution like the one you coded above :/

from osx-script-stuff.

crjstobal avatar crjstobal commented on July 19, 2024

Thanks Jonas! It works like a charm :)

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

I am running 10.12.5 and copied the code from your script exactly as is and no attachments get moved to the Downloads folder. Any thoughts?

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

@taxman11 Try the new version I uploaded for this issue: #3

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

Still does not work for me. Using version 3.2.7 of Airmail.

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

Are you sure the mail rule is set up correct? At the bottom of the rules window is a "Preview" button. See, if there are mails with attachments found. Then you can apply the rule to the matched mails to see if the script is working.

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

Open the applescript editor application, copy and paste the script code into a new document and append these two lines:

tell application "Airmail 3" to set theMessage to selected message
my processMessage(theMessage)

Open AirMail, select the message with the attachment and run the script in the editor. Does it work that way?

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

Forgive my ignorance but where exactly should I add this additional code you posted?

Should I add it immediately after the end processMessage?

And how do I select a message in Airmail that the script should apply to and run that in the script editor?

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

The full script would look like this

property DOWNLOADS : "~/Downloads"

on processMessage(theMessage)
	try
		tell application "Airmail 3"
			repeat with anAttach in mail attachments of theMessage
				set aFilename to filename of anAttach
				set aFile to quoted form of POSIX path of aFilename
				do shell script "cp " & aFile & " " & DOWNLOADS
			end repeat
		end tell
	end try
end processMessage

tell application "Airmail 3" to set theMessage to selected message
my processMessage(theMessage)

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

from osx-script-stuff.

jneug avatar jneug commented on July 19, 2024

You can change the path at the top of the script:

property DOWNLOADS : "~/Desktop/Temp"

But you shouldn't use this version in any Airmail rule. If it is working by manually running the script from the script editor the problem seems to be how you setup your rule in Airmail.

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

from osx-script-stuff.

taxman11 avatar taxman11 commented on July 19, 2024

Was wondering if you had a chance to respond to my message a couple of days ago about the Downloads folder. Just out of curiosity, I tried changing the property Downloads as you mentioned and the attachments did not copy so it appears the "sandboxing" issue I have read about may in fact be true.

On another note, using the code as is, I have an issue when I receive multiple emails in close proximity that both contain a file, for example called Doc - 05-24-17 -2-39 PM.pdf. In that case, only one of the files makes it to the destination folder since they have the same name. Is it possible to add some code to append a digit or something else to the duplicate filename so both files are copied?

Thanks

from osx-script-stuff.

crjstobal avatar crjstobal commented on July 19, 2024

from osx-script-stuff.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.