Apple Script

ClivePCP

Registered
I have an apple script designed, however i need it to do a bit more.

At the moment it downloads attached pdfs and places them in a folder on my desktop. The problem is if i have attachment the same name it overwrites current I need it to NOT overwrite but add.

I would also like this script to set emails as read and move to a folder. Here is the current script.

using terms from application "Mail"
on perform mail action with messages The_Messages
set save_Folder to my GetFolderName()
tell application "Mail" to repeat with This_Message in The_Messages
tell contents of This_Message
if (count (mail attachments)) > 0 then
repeat with an_attachment in (get every mail attachment)
set att_save_file to save_Folder & (an_attachment's name)
save an_attachment in att_save_file
end repeat
end if
end tell
end repeat
end perform mail action with messages
end using terms from

--------------
to GetFolderName()
return (path to desktop as text) & "PCPostit:"
end GetFolderName
 
I like to use a timestamp to fix the naming issue, like this:
Code:
tell application "Finder"
	if file att_save_file exists then
		set AppleScript's text item delimiters to "."
		set ext to (the last text item of att_save_file)
		set fname to text items 1 thru ((the number of text items of att_save_file) - 1) of att_save_file
		set AppleScript's text item delimiters to ""
		set att_save_file to fname & " " & (do shell script "date '+%Y-%m-%d %H-%M-%S'") & "." & ext as text
	end if
	return att_save_file
end tell

You may want to include further testing to see if the new file name exists if there's a chance you'll do more than one per second (or for some reason you have a post-dated timestamp on an older file, perhaps due to time zone differences).

I've never used Mail much so I'm not sure about the other question.
 
Back
Top