Automators 2: Email Automation

episode

#41

Oh well, turns out it was not “simple enough” - at least for me.

When I modified the script to read as below, I don’t get first name greetings. Instead, the applescript itself is pasted into the mail message.

    tell application "System Events"
	tell process "Mail"
		tell text field "To:" of window 1
			get count of UI elements
			if result is 1 then
				set theToRecipient to (value of UI element 1)
				return word 1 of theToRecipient
			else if result is 2 then
				set the1stToRecipient to (value of UI element 1)
				set the2ndToRecipient to (value of UI element 2)
				return word 1 of the1stToRecipient & " and " & word 1 of the2ndToRecipient
			else if result is 3 then
				set the1stToRecipient to (value of UI element 1)
				set the2ndToRecipient to (value of UI element 2)
				set the3rdToRecipient to (value of UI element 3)
				return word 1 of the1stToRecipient & ", " & word 1 of the2ndToRecipient & " and " & word 1 of the3rdToRecipient
			else if result is greater than 3 then
				return "all"
			end if
		end tell
	end tell
end tell

#42

If you are using TextExpander, make sure you have the snippet format set as AppleScript.


#43

oh duh!

(Now it works.)

Thanks!


#44

Or Typinator – works perfect!


#45

Is there a possibility to use this script in fullscreen-mode? does not seem to work for me… :frowning:


#46

I’ve had some odd issues with other applescript not working in full screen - snippets to get current browser URL etc. - I believe it’s because AS doesn’t recognise the full screen as window 1. Here’s how I fixed it in those:

# get the frontmost window - this will fail in full screen
try
tell application "Safari" to return name of current tab of window 1
return
end try

# get window 2 - for full screen
tell application "Safari" to return name of current tab of window 2

end run

#47

Thanks for the answer! Strangely it worked with the script by iwarwick further up in this thread. That one works within full screen mode and window mode!


#48

Hi Mark, Could you kindly share with me how you did that with KM? I’m very the much the noob and am waiting patiently for David’s new field guide to come out so that I can learn how to use this!