Mail.app: Send Interactive Screenshot to To Recipient


set toRecipientAddress to "kniazidis.rompert@gmail.com"
my sendScreenShot(toRecipientAddress)


on sendScreenShot(toRecipientAddress)
	set buttonReturned to button returned of (display dialog "Capture selection to Mail or to the Desktop." buttons {"To Mail", "To Desktop", "Cancel"} default button "Cancel" cancel button "Cancel" with title "Welcome to Take Screenshot Interactively.app")
	if buttonReturned is "To Desktop" then
		my createScreenchotInteractivelly(path to desktop folder)
	else if buttonReturned is "Cancel" then
		display notification "User cancelled"
	else
		set tempFolder to path to temporary items from user domain
		set theDate to my createScreenchotInteractivelly(tempFolder)
		tell application "Finder"
			sort files of tempFolder by modification date
			set recentScreenshot to (last item of result) as alias
		end tell
		tell application "Mail"
			activate
			tell (make new outgoing message with properties {subject:"Data you requested", content:(theDate & return & return), visible:true})
				make new to recipient at end of to recipients with properties {address:toRecipientAddress}
				tell content to make new attachment with properties {file name:recentScreenshot} at after the last paragraph
				delay 1
				send
			end tell
		end tell
	end if
end sendScreenShot


on createScreenchotInteractivelly(theFolder as alias)
	do shell script "DATE=`date '+%Y-%h-%d-%H-%M-%S'`;
			FILE=" & POSIX path of theFolder & "screenshot-${DATE}.png;
			screencapture -i $FILE;echo ${DATE}"
end createScreenchotInteractivelly