Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to (somewhat) merge threads in Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to (somewhat) merge threads in Mail.app
Authored by: leenoble_uk on Oct 21, '04 11:20:14AM

I fixed the script after I submitted it. One additional line fixes both issues.

tell application "Mail"
	set theSubjectList to {}
	set themessages to selection as list
	repeat with msg in themessages
		set thisSubject to (subject of msg as string)
		if thisSubject is not in theSubjectList then
			set theSubjectList to theSubjectList & {thisSubject}
		end if
	end repeat
	
	set theNewSubject to (choose from list theSubjectList with prompt "Choose the subject of the merged thread…") as string
	
	if theNewSubject is in theSubjectList then
		repeat with msg in themessages
			set subject of msg to (theNewSubject)
		end repeat
		move msg to mailbox "INBOX" of account of mailbox of msg
	else
		display dialog "Action cancelled"
	end if
end tell

but it only works in your inbox. I'm sure someone can alter it to work in any mailbox.

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.

[ Reply to This | # ]

A script to (somewhat) merge threads in Mail.app
Authored by: leenoble_uk on Oct 21, '04 12:44:02PM

This version lets you type in whatever you like for the subject...

tell application "Mail"
	set theSubjectList to {}
	set themessages to selection as list
	set messageTitle to button returned of (display dialog "Thread name…" buttons {"New", "Select From Existing…"} default button 2)
	repeat with msg in themessages
		set thisSubject to (subject of msg as string)
		if thisSubject is not in theSubjectList then
			set theSubjectList to theSubjectList & {thisSubject}
		end if
	end repeat
	
	if messageTitle is "New" then
		set theNewSubject to (text returned of (display dialog "Type new subject" default answer "NEW THREAD")) as string
	else
		set theNewSubject to (choose from list theSubjectList with prompt "Choose the subject of the merged thread…") as string
	end if
	
	if theNewSubject is not "false" then
		repeat with msg in themessages
			set subject of msg to (theNewSubject)
			move msg to mailbox "INBOX" of account of mailbox of msg
		end repeat
	else
		display dialog "Action cancelled"
	end if
end tell

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.

[ Reply to This | # ]

A script to (somewhat) merge threads in Mail.app
Authored by: leenoble_uk on Oct 21, '04 12:52:23PM

OK, Final version. Lets you choose or type and includes options to rename the message to what it was called originally, providing it is held within the header text.

tell application "Mail"
	set theSubjectList to {}
	set headList to {}
	set themessages to selection as list
	set messageTitle to button returned of (display dialog "Thread name…" buttons {"New", "Select From Existing…"} default button 2)
	repeat with msg in themessages
		set theHeaders to headers of msg as list
		set thisSubject to (subject of msg as string)
		repeat with head in theHeaders
			if (name of head as string is "Thread-Topic") and (content of head as string is not in theSubjectList) then
				set theSubjectList to theSubjectList & {(content of head as string)}
			else if thisSubject is not in theSubjectList then
				set theSubjectList to theSubjectList & {thisSubject}
			end if
		end repeat
		if thisSubject is not in theSubjectList then
			set theSubjectList to theSubjectList & {thisSubject}
		end if
	end repeat
	
	if messageTitle is "New" then
		set theNewSubject to (text returned of (display dialog "Type new subject" default answer "NEW THREAD")) as string
	else
		set theNewSubject to (choose from list theSubjectList with prompt "Choose the subject of the merged thread…") as string
	end if
	
	if theNewSubject is not "false" then
		repeat with msg in themessages
			set subject of msg to (theNewSubject)
		end repeat
		move msg to mailbox "INBOX" of account of mailbox of msg
	else
		display dialog "Action cancelled"
	end if
end tell

It also only needs to do the move message line once on a single message, after the renaming is complete.

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.

[ Reply to This | # ]