newbie scripter alert

Hey guys. just another newbie looking for some help here. I wrote a script that should take a selection of emails and copy them to a single Microsoft word File. Problem is I can’t seem to get the current_email variable into the clipboard to paste to the Word document. What am I doing wrong or is there a better way to do this?

also, I am wondering about the List function and if they are ordered or is there a function that orders them for you? If not does anyone have a quicksort or heapsort function that works in Applescript? I’m going to be dealing with about 4000 emails so I can’t use non-efficient sorting functions.

Anyway, here is my code. Thanx for any help you can offer. :smiley:

tell application "Mail"
	set the_selection to (selection)
	
	repeat with current_selection in the_selection
		set current_subject to (subject of current_selection)
		set current_content to (content of current_selection)
		
		set current_email to current_subject & return & current_content & return & return
		set the clipboard to current_email
		
		tell application "Microsoft Word"
			paste
		end tell
	end repeat
	
end tell

What version of Word?

Hi,

When you copy to clipboard, the process that can copy to clipboard needs to be frontmost (activate). Mail uses certain text encodings and its text need to be handled carefully. Note that coercing to string (plain text) won’t work in many situations with Mail text.

tell application “Mail”
activate
set the_selection to (selection)

repeat with current_selection in the_selection
	set current_subject to (subject of current_selection)
	set current_content to (content of current_selection)
	
	set current_email to (current_subject & return & current_content & return & return) as string
	set the clipboard to current_email
	
	tell application "Microsoft Word"
		activate
		paste
	end tell
end repeat

end tell

I use a repeat loop and ‘ascii character’/‘ascii number’ with Mail text encoding to convert each character to plain text. This takes a long time but is better than wrestling with the encodings.

gl,

Thanx kel and digest4d. That worked kel.

Hi xMiles Tegx,

Glad it worked. I’d replace those Mail linefeeds with carriage returns before setting the clipboard. It’s easy.

gl,