adding multiple URLs to the content of Mail message

I have been hacking on the following script. It was originally made to make a new message in Mail with the URL in the content and the title as the subject. I want to leave the new window in Mail open and continue to add more URLs to the same message.

My problem is that after selecting the open “new message” window in Mail, I cannot update the content and the script instead will generate an error which throws me into “on error” section and another “new message” window is created. How can I clean this up and fix it?

tell application “Safari”
ignoring case
set theURL to URL of front document
set theSource to source of front document
set AppleScript’s text item delimiters to “title>”
set theSource to second text item of theSource
set AppleScript’s text item delimiters to “</”
set theTitle to first text item of theSource
end ignoring
end tell

tell application “Mail”
try
set new_msg to window “New Message”
–error occurs here
set theContent to content of new_msg
set content of new_msg to theContent & theTitle & return & theURL & return & return
on error
set accountAddresses to (email addresses of first account)
set fromAddress to first item of accountAddresses
set theMessage to make new outgoing message
set visible of theMessage to true
set content of theMessage to theTitle & return & theURL & return & return
end try

end tell

Hi,

you can only change the properties of an currently created outgoing message like


tell application "Safari"
	set {URL:theURL, name:theTitle} to front document
end tell

tell application "Mail"
	set accountAddresses to (email addresses of first account)
	set fromAddress to first item of accountAddresses
	set theMessage to make new outgoing message with properties {visible:true, content:theTitle & return & theURL & return & return}
	set sender of theMessage to fromAddress
end tell

Note: the title of a web site can be retrieved easily with the property name.

Ok, let me get this right. You are saying that I cannot change a new mail message once I have created it? Does that mean the answer is to copy the old message, delete it, and create a new one with the extra text in it?

Yes, you can change the properties only in the message which appears after the make new outgoing message command
which the message is not saved yet

I have been trying to copy the content of the new message (not saved or sent). I seem to get an error when I try this. Is there a way to copy the content of this message?

of course


property theContent : "This is a line"
property theSubject : "subject"

tell application "Mail"
	activate
	set newMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theContent & return & "This is another line"}
	tell newMessage
		set myContent to content
	end tell
	display dialog myContent
end tell