How do I massage this script

The following script is designed to parse a mail message, save it as a tab delimited text file which I can then import into daylite.

The problems are it saves the file on my desktop and it replaces any earlier versions with the same name. So if I ran the script three times in one day only the last time would be in the file. I am using mail convert to convert the file to the proper format. I have a second drive named hitachi which I would like to save the files in a folder on.

below is the applescript

Convert Mail to Tab Text

set mycounter to 0
set myText to ""

(*
You can uncomment out the appropriate line depending on whether you wish to use TextEdit or BBedit. Only one line should be uncommented. TextEdit is the default.
*)

--set myTextEditor to "BBEdit"
set myTextEditor to "TextEdit"

tell application "Finder"
	if myTextEditor is "TextEdit" then
		set myhomename to name of home as text
		set mydrive to startup disk
		set filename to name of startup disk & ":Users:" & myhomename & ":desktop:Email Contents" as string
	else
		set myhomename to name of home as text
		set mydrive to startup disk
		set filename to name of startup disk & ":Users:" & myhomename & ":desktop:Email Contents" as string
	end if
end tell

tell application "Mail"
	set mymessages to the selection as list
	repeat with mymessage in mymessages
		set myText to myText & the source of mymessage
	end repeat
end tell

if myTextEditor is "TextEdit" then
	-- Send messages to TextEdit to save
	tell application "TextEdit"
		activate
		make new document at the beginning of documents with properties {text:myText}
		set modified of front document to yes
		save front document in filename
		quit
	end tell
else
	-- Send messages to BBEdit to Save
	tell application "BBEdit"
		activate
		
		-- create the file
		make new text window with properties {name:filename, contents:myText}
		
		-- save the file in the folder created above
		save text window 1 to filename
		close text window 1
		
		-- exit BBEdit
		quit
	end tell
end if

tell application "Mail Convert"
	-- launch Mail Convert
	activate
	
	-- process the file created by BBEdit
	Process filename
	
	-- exit Mail Convert
	Quit
end tell

I don’t know anything about Mail Convert, but I assume it writes to the desktop whether you like it or not. I don’t know how it sets the file name, however. What you need to do is follow your script with a short segment to rename the file as soon as it is created on the desktop, appending a time stamp for instance or numbering scheme, and then move it to a folder somewhere else.

Hi,

short version without the Mail Convert stuff, because I don’t have it.
If the data to write on disk is only plain text, AppleScript’s own read/write commands are better
than involving a text editor.

set filename to ((path to desktop) as Unicode text) & "Email Contents"

set myText to ""
tell application "Mail"
	set mymessages to the selection as list
	repeat with mymessage in mymessages
		set myText to myText & the source of mymessage & return & return
	end repeat
end tell

set ff to open for access file filename with write permission
write myText to ff starting at eof
close access ff

New messages will be appended to the file “Email Contents”.
One problem reading the source of the mail(s) is: you get indeed all informations but
often the wrong text encoding. It would be better to compose the text out of the several properties of the message
(headers, sender, recipient, subject, contents etc.)