Hi!
I am using Sonoma 14.5.
I have script that activates from a mail rule for emails from a specific sender.
The script works perfect when using it in the form that I got it, which downloads the attachment to the downloads folder. I have also tried to put the attachment in another folder inside the downloads folder, and that works as well.
What i would want though is to download the attachment to a folder on the desktop, and then nothing happens. I cant get the attachment to download to the desktop or the subfolder.
I am thinking this is not a syntax error, but i can’t figure out why it isn’t working.
´´´ using terms fromapplication “Mail”
onperform mail action with messages theMessages for rule theRule
set downloadsHFSpath to (path todownloads folder rule type string) & “Fakturor:”
tellapplication “Mail”
repeatwith oneMessage in theMessages
repeatwith oneAttachment in (mail attachmentsof oneMessage)
save oneAttachment in (downloadsHFSpath & name of oneAttachment)
endrepeat
endrepeat
´´´
I have tried with set downloadsHFSpath to (path to desktop folder rule type string) & “Fakturor:”
but that wont work. Neither will any combinations like it, like using only desk instead of desktop or omitting the word folder.
Any help would be most appreciated!
(edit: I cant get the syntax for the scripting to work when posting?)
So, to first address the posting syntax… use the backtick (```) or grave accent (U+0060) — ie the key above the tab (on an English keyboard). Your post has the acute accent.
As to the other issue, the easiest thing to do is move the set ‘path’ command outside of the using terms block, which you may not even need. You can also use the syntax below inside the block but in general, there isn’t a reason to put the set command inside the using terms block. Note the two sets of parentheses in the line.
What seems to be happening is that upon compiling, the verbiage is getting changed in a confusing manner. This is probably because there is some overlap with some protected Mail terms.
Also, you need to close each of the blocks (on perform, using terms, tell, repeat). I can’t see whether your complete script does so but what’s posted above requires them in order to compile. The ‘on perform’ and ‘using terms’ blocks should probably both be ended before the ‘tell app mail’ begins — see below.
Hopefully, this will work (but I haven’t tested it).
set desktopDownloads to ((path to desktop) as text) & "Facturor:"
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
end perform mail action with messages
end using terms from
tell application "Mail"
repeat with oneMessage in theMessages
repeat with oneAttachment in (mail attachments of oneMessage)
save oneAttachment in (desktopDownloads & name of oneAttachment)
end repeat
end repeat
end tell
Thank you very much for your effort!
Couldn’t get your code to work though. Nothing was saved.
I’ll paste my original code now with the correct accent.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set downloadsHFSpath to (path to downloads folder rule type string) & "Fakturor:"
tell application "Mail"
repeat with oneMessage in theMessages
repeat with oneAttachment in (mail attachments of oneMessage)
save oneAttachment in (downloadsHFSpath & name of oneAttachment)
end repeat
end repeat
end tell
end perform mail action with messages
end using terms from
So this is the way my script is formatted, and yes it changes somewhat when compiling. However this script works perfectly, the attachment is saved to the downloads/fakturor folder. Its just that when I try to change where to save the attachment, it will not work in the desktop folder.
That part it is written as: “path to downloads folder as string” but changes “as” to “rule type” when compiled, like below.
set downloadsHFSpath to (path to downloads folder rule type string) & "Fakturor:"
Ah well. Unless it is obvious to you why it wont work to solely switch the two path references in the script to the to desktop folder, I guess i will just have to accept it as it is.
Guess I will have to have a shortcut on the desktop instead.
Thanks for your effort anyways!