Thanks, but that doesn't work. The colon is added to the name with the line...
I've tried to use the GUI, and it works, but I needed to make it bullet proof, hence all the calls to activate 'Mail' during saving. FWIW I've had a long standing bug report since Lion, that saving mail as rtfd's with attachments does not save folders in the rtfd. I suspect the necessity to add the 'file' command has also stopped folders being saved.
global newFolderName
global ptd
global posixPath
on run
set ptd to path to desktop
set posixPath to POSIX path of ptd
tell application "Mail"
activate
if (count of windows) > 1 or (count of windows) = 0 then
quit
delay 2
activate
end if
set the visible of every window to true
set selected mailboxes of message viewers to mailbox "* items to shift"
set tempmessages to messages of mailbox "* items to shift"
if (count of tempmessages) > 0 then
repeat with MessageCount from 1 to count of tempmessages
my CreateFolder()
activate
set the selected messages of message viewers to message MessageCount of mailbox "* items to shift"
my saveAttachments()
delay 1
end repeat
end if
end tell
end run
on saveAttachments()
tell application "Mail" to activate
tell application "System Events" to tell process "Mail"
if enabled of menu item "Save Attachments…" of menu 1 of menu bar item "File" of menu bar 1 is true then
--say "menu exists"
click menu item "Save Attachments…" of menu 1 of menu bar item "File" of menu bar 1
repeat until exists pop up button 1 of group 1 of sheet 1 of window 1
tell application "Mail" to activate
end repeat
select pop up button 1 of group 1 of sheet 1 of window 1
tell application "Mail" to activate
keystroke (posixPath & "/" & newFolderName)
tell application "Mail" to activate
keystroke return
tell application "Mail" to activate
repeat until exists button 1 of sheet 1 of window 1
tell application "Mail" to activate
end repeat
tell application "Mail" to activate
click button 1 of sheet 1 of window 1
end if
end tell
end saveAttachments
on numberAdjust(theNumber)
set theNumber to theNumber as number
if theNumber = 0 then return "00"
if theNumber < 10 then return "0" & theNumber
return theNumber
end numberAdjust
on CreateFolder()
set WorkingDate to (current date) - (time to GMT)
set theYear to year of WorkingDate
set theMonth to my numberAdjust(month of WorkingDate as number)
set theDays to my numberAdjust(day of WorkingDate)
set theHours to my numberAdjust(hours of WorkingDate)
set theMinutes to my numberAdjust(minutes of WorkingDate)
set theSeconds to my numberAdjust(seconds of WorkingDate)
set newFolderName to (theYear & "-" & theMonth & "-" & theDays & " " & theHours & theMinutes & theSeconds & "Z") as text
set newFolderPath to (ptd & newFolderName) as text
tell application "Finder"
if not (exists folder newFolderPath) then (make new folder at ptd with properties {name:newFolderName})
end tell
end CreateFolder