Automators 2: Email Automation

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

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

oh duh!

(Now it works.)

Thanks!

Or Typinator – works perfect!

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

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

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!

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!

@RosemaryOrchard I would also love to see this macro, it would be a massive help for a project I am working on :blush:

Creating an e-mail, utilising Keyboard Maestro, based on a file appearing in a folder could be something as simple as this:

Use a folder trigger set to check for item additions. If it finds a new file, then it will simply utilise the send mail message action. I’ve used the %TriggerValue% variable as an example to show how you could use that to even include the file as an attachment to the mail.

I also set it to leave open so that I could show you the result of adding an image file to the watched folder.

If you wanted to check for a very specific file, you could do this by checking for the name for example with an if action.

Hope that helps.

1 Like

Thank you very much for such a detailed answer, I will have to try the %TriggerValue% variable, perhaps that was what was eluding me.

I have an answer using this system which I stumbled upon on the KM forms, but I don’t understand it, or how it works, I like your solution much better.

For what it’s worth, this script returns the text in the To field with the current latest version of Outlook v16.58.

tell application "System Events"
		tell process "Microsoft Outlook"
			tell front window
				tell splitter group 1
					tell scroll area 1
						tell text field 1
							#set uiElems to entire contents
							set myVar to value of static text 1
							#display dialog uiElems as text
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell	
1 Like

Updated AppleScript to work with the latest version of Microsoft Outlook for Mac (v16.68):

tell application "System Events"
	tell process "Microsoft Outlook"
		tell text field 1 of scroll area 1 of splitter group 1 of front window
			get count of static text
			if result is 1 then
				set theToRecipient to (value of static text 1)
				return word 1 of theToRecipient
			else if result is 2 then
				set the1stToRecipient to (value of static text 1)
				set the2ndToRecipient to (value of static text 2)
				return word 1 of the1stToRecipient & "/" & word 1 of the2ndToRecipient
			else if result is greater than 2 then
				return "all"
			end if
		end tell
	end tell
end tell

Thanks @jaco for the nudge in the right direction (even if it was 11 months ago)!

CC: @Mloveday5 in case you’re still looking for a fix.

1 Like

Hi @DJLein

thanks for your work and your shared code. Unfortunately, your code no longer works in Microsoft Outlook for Mac (v16.78). In particular, the value of the recipient’s text field is empty. Have you already found a workaround for that? The weird thing is, that you can write into the recipient text field but not read any autocompleted address.

I would appreciate any help, for solving this bug.

1 Like