This script provides a drop down menu to choose an existing “parent” folder where a new sub-folder is created. The new sub-folder is named after the subject of the first message and then files the selected message/s in the new sub-folder. I have it working, but sometimes additional text follows the first two words in the subject (which is the only text I want the sub-folder called) and either causes an exsessively long sub-folder name or it can even cause an error if the subject is to long resulting in multiple sub-folders of the new sub-folder.
So using “text” or even setting the new sub-folder as the subject of the message will work, but I’m trying to use just the first 2 to 3 words of the subject. Ive tried the below with no luck. Thoughts on how to identify the words (not text) of the subject? Thanks!
set theSubject to words of theSubject
set AppleScript's text item delimiters to ASTID
set theSubject to word 1 thru 3 of theSubject
set folderName to theSubject as Unicode text
Here’s the working script thus far:
tell application "Mail"
activate
set theSelectedMessages to selection
set theselectedmessage to item 1 of theSelectedMessages
set theSubject to the subject of item 1 of theselectedmessage
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "Fwd:"}
set AppleScript's text item delimiters to ""
set theSubject to text of theSubject
set AppleScript's text item delimiters to ASTID
set theSubject to text 1 thru 20 of theSubject
set folderName to theSubject as Unicode text
(*Drop down list of folders to choose where sub-folder will be created*)
set myList to {"2012/Group 1", "2012/Group 2", "2012/Group 3", "2012/Group 4", "2012/Group 5", "2012/Group 6", "2012/Group 7", "2012/Group 8"}
choose from list myList with title "Move Message(s)" with prompt "Choose which group" default items {"aaWork/zApplications/2012"}
set selectedMailBox to result as string
(*Making the new subfolder and moving the message/s into it*)
if selectedMailBox is "2012/Group 1" then tell application "Mail"
set Customfolder to "aaWork/zApplications/2012/Group 1"
if not (mailbox folderName exists) then
make new mailbox with properties {name:Customfolder & "/" & folderName}
repeat with eachMessage in theSelectedMessages
move eachMessage to mailbox (Customfolder & "/" & folderName)
end repeat
end if
end tell
(*...for all 8 groups*)
tell application "Mail"
activate
end tell
end tell