I could do with some sort of tutorial/guide for using mail with applescript. Does anyone kknow of any free online sites?
Also, I am needing to adapt a script that someone on here kindly sent me in mail. i dont know if it is possible, but here is what I need to do.
I have a script that will save the body of an email in a folder, when the subject matches a rule setup. This is fine, but I need so set up some sort of delay, so that if 2 messages are recieved, with the same subject line, (or more) I need to delay the saving of subsequent text files. The 1st text file is deleted within about 10 seconds if that helps.
I know there is a command
delay 10
to delay the scrip for 10 seconds, but I dont think in this instance it would do the neccesary.
Putting the delay before the “end repeat” should work if the delay is long enough, but it will delay every time. Maybe a repeat of a short delay while the file is being written will work - I’ve seen something like that somewhere, but I can’t remember where right now.
If you use this line
set fileName to subject & "_" & (do shell script "date +%m/%d/%y/%T") & ".txt"
the file name will have the date including the time to the second (mm/dd/yy/hh:mm:ss) which decreases the chance of a duplicate name - I guess it would eliminate it if used with a 2 or three second delay.
Or you could sequentially add a number to the end subject of the messages being processed before it is put into the file name - not sure where I saw that either - but that combined with the date to the second would probably eliminate the need for any delay.
Does that help?
EDIT: When I get a chance I’ll find the information that escapes me right now. Maybe somebody else will have something sooner.
I’m going to look up the repeat options I mentioned for my own benefit. I’d like them to be things I know how to do without a reference. My AppleScript foundation could use some (a lot of) shoring up.
The simple delay option worked a treat before the end repeat.
Cheers.
Going back to my other question, I guess what I am looking for is some documentation regarding syntax, loops, ifs, etc and how to properly contruct lines in AS.
A way to absolutely guarantee that a file name is unique is to append the BSD “uuidgen” string to it.
This string combines the MAC address of the computer it is running on with the current time, so it is never possible for there to be a duplicate.
Example script:
tell application "Finder"
set theFile to (choose file)
set theUUID to do shell script "uuidgen"
set {theNameExtension, theFileName} to {name extension, name} of (info for theFile)
if theNameExtension is not missing value then
set name of theFile to (text 1 thru ((offset of theNameExtension in theFileName) - 2) of theFileName) & theUUID & "." & theNameExtension
else
set name of theFile to theFileName & theUUID
end if
end tell