Hi
I am after a bit of help,
I need a script that can be added to a rule in mail.app that will save a attachment file from a Subject related email to a folder on my desktop.
The Subject will always have “TRM_FM” at the begining and then a number.
The attachment will be a .txt file.
The Folder will be called “Attachments”
any ideas?
Here’s a starting point. It’s a script of mine that does something similar, only it saves the contents of the email. You should be able to change it (or get ideas) to something like what you want.
using terms from application "Mail"
--save selected messages to text files
on perform mail action with messages messageList
if length of messageList is not 0 then
copy messageList to myMessages
display dialog "Export selected message(s)?"
if the button returned of the result is "OK" then
set theFolder to choose folder with prompt "Save Exported Messages to..." without invisibles
repeat with theMessage in myMessages
set theFile to ((theFolder) as Unicode text) & (subject of theMessage) as Unicode text
set theContent to (content of theMessage) as Unicode text
try
set theFileID to open for access theFile with write permission
write theContent to theFileID
close theFileID
on error
display dialog "Can't write message"
end try
end repeat
display dialog "Done exporting " & length of myMessages & " messages."
end if
end if
end perform mail action with messages
end using terms from
using terms from application "Mail"
on run
tell application "Mail" to set mySelection to selection
tell me to perform mail action with messages (mySelection)
end run
end using terms from
Thanks I shall give it a go.
Here is a modification of a script that I use:
--Saves any SINGLE attachment to the 'Mailfiles' folder of the Desktop
using terms from application "Mail"
on perform mail action with messages The_Messages
set Save_folder to SaveFolder()
tell application "Mail" to repeat with This_Message in The_Messages
set save_file to (Save_folder & (the name of first mail attachment of This_Message))
save first mail attachment of This_Message in save_file
end repeat
end perform mail action with messages
end using terms from
---------------------------------------------------------------------
on SaveFolder()
set a to ((path to desktop as Unicode text) & "Mailfiles:")
end SaveFolder
There are two threads on this topic that may interest you, here they are:
http://bbs.applescript.net/viewtopic.php?id=16548
http://bbs.applescript.net/viewtopic.php?id=15668
Good luck