need help automating Apple Mail for extra simplicity.

I’m designing a system for a homebound senior with mild dementia. At this point, he only needs to send and receive email from one person. It has to be very simple and consistant. My strategy is to make Fkey activated Applescripts. One such Applescript will launch Mail, create a new message, address it and leave the cursor blinking in the body of the message. I glomed the script below but need to add some actions and don’t know how.

What I would like it to do:
-Close the main mail window when the new message is created so there is just one window open.
-Not create a new message if a new message already exists. This is in case the Fkey is pressed several times.
-Hide other applications.
-It would be nice to have a dialog box that announces that a message has been sent and then OKs itself after a few seconds.

This is what I have so far:
tell application “Mail”
set theMessage to make new outgoing message with properties {visible:true, subject:“hello”, content:“tExT”}
tell theMessage
make new to recipient at end of to recipients with properties {name:“jane doe”, address:"jane@jane123.net"}
end tell
end tell

Thanks in advance to anyone who can help, this means a lot to this person (and me too!):slight_smile:

Hi ronan,

to avoid a second script which detects if the message has been sent,
the message text will be entered in an AppleScript dialog text field,
then the message will be sent automatically

Try this:

property theSubject : "hello"

tell application "System Events" to tell process "Mail" to exists window theSubject
if result is false then
	tell application "System Events" to set visible of (processes whose name is not "Mail" and visible is true) to false
	set defAnswer to return & return & return & return & return & return & return & return & return & return & return & return
	set theContent to text returned of (display dialog "Enter message text" default answer defAnswer buttons {"OK"} default button 1)
	tell application "Mail"
		try
			close (1st window whose name is not theSubject)
		end try
		set theMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theContent}
		tell theMessage
			make new to recipient at end of to recipients with properties {name:"jane doe", address:"jane@jane123.net"}
		end tell
		activate
		send theMessage
		display dialog "Message " & theSubject & " has been sent" buttons {"OK"} default button 1 giving up after 5
	end tell
end if