Sending Text or Picture to mail from clipboard

I have been working on a script that uses the clipboard into mail. Using some of the examples from this form i got it to work only partially. I need help with the keystroke "v"as i am loosing the focus on the body of mail and it will not paste my picture. It does work if i put my cursor in the body of my outgoing mail and use command “v” manually. The script works fine if the clipboard has text. If someone could please direct me in the right direction. Also do i have the error checking correct.
Thanks,
Polishprince


--A Script to take clipboard to Mail regardless of content or class
--Check to see if contents of clipboard is text or graphics

set thisFile to "Important Data for you"
set cbContent to (the clipboard)
set cbClass to class of (the clipboard)
try
	if cbContent is not {} then
		
		if ((cbClass is picture) or ((cbClass is record))) then
			--display dialog "Its an image" --Used only for syntax checking
			
			tell application "Mail"
				activate
				make new outgoing message at end of outgoing messages with properties {content:thisFile, subject:"Data you requested", visible:true}
				
				
				
				tell application "System Events"
					tell (application process 1 whose frontmost is true)
						keystroke "v" using command down
					end tell
				end tell
				
				
			end tell
			
		else
			--It is not a picture so cbContent will be pasted in as text
			tell application "Mail"
				--display dialog ((cbClass as string) & " (" & cbContent & ")") as string --Used only for syntax checking
				
				make new outgoing message at end of outgoing messages with properties {content:cbContent, subject:"Data you requested", visible:true}
			end tell
			
		end if
		
	end if
on error
	set cbContent to {}
	display dialog "An error has occured"
end try

Model: Mac G5 dual 250
AppleScript: version 2.2
Browser: Safari 523.10
Operating System: Mac OS X (10.5)

See this topic: http://bbs.applescript.net/viewtopic.php?pid=91306#p91306

Adam
That is the example that got me started on this project. The problem is that example takes the graphics from a file on the desktop and not directly from the clipboard. I use the clipboard very much and this would be awesome if it would work. The problem with my script is i don’t know how to have the cursor hold the focus in the body of my mail.
polishprince

Hello
Maybe i am trying to do something that can’t be done in Applescript. Is it even possible to send the graphics content of the clipboard directly to the body of an email message.
Could this even be done with a shell script.
Thanks for any help that you can provide.
Polsihprince

Hi,
I’m not to sure what problems you’re having but please give this a try and see if it helps

tell application "Mail"
	activate
	set newMessage to make new outgoing message with properties {subject:"test", content:"test"}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {name:"My Email", address:" email@address.com"}
	end tell
end tell

tell application "System Events"
	tell process "Mail"
		keystroke "v" using command down
	end tell
end tell

I tried this with an image on the clipboard and pasted directly into the body of the mail.
Thanks,
Nik

Blend3
This is what i was looking for. This script works also with “Text” or “Graphics” in the clipboard.
I really appreciate the help. You guys are great.
Thanks,
Polishprince