AppleScript for Selecting Outlook

I want to have Outlook select a specific signature then create a new message with the body content of the signature .

tell application "Microsoft Outlook"
	activate
	set TheRecipient to the clipboard
	set theMessage to make new outgoing message with properties {sender:{name:"Cory Schmaltz", address:"rangeviewmarketing@gmail.com"}, subject:"100 Chiropractor leads!"}
	tell theMessage
		make new to recipient with properties {email address:{address:TheRecipient}}
		tell application "System Events"
			tell process "Microsfot Outlook"
				tell toolbar of splitter group 1 of window 1 of application process "Outlook"
					#click (menu item 4 of "Toolbar" of splitter group 1 of window 1 of application process "Outlook")
					#set uiScript to "click UI Element 4 of group \"Toolbar\" of splitter group 1 of window 1 of application process \"Outlook\""
					-- Initial
					#delay 2.639726
					#set timeoutSeconds to 2.0
					#set uiScript to "click menu item \"Initial\" of menu 1 of UI Element 4 of group \"Toolbar\" of splitter group 1 of window 1 of application process \"Outlook\""
					#delay 2
				end tell
			end tell
		end tell
	end tell
end tell

#send theMessage

this is another portion that I tried to get working but I can't seem to get it to select/change:

tell application "Microsoft Outlook" to activate
tell application "System Events"
	-- turn on UI automation - may throw a permissions dialog
	if UI elements enabled is false then set UI elements enabled to true
	
	click menu item "Preferences..." of menu 1 of menu bar item "Outlook" of menu bar 1 of application process "Outlook"
	click item 1 of (buttons of window "Outlook Preferences" of application process "Outlook" whose description is "Signatures")
	set timeoutSeconds to 2.0
	set timeoutSeconds to 2.0
	set uiScript to "click menu item \"Cory Schmaltz (Rangeviewmarketing)\" of menu 1 of pop up button 3 of group 2 of window \"Signatures\" of application process \"Outlook\""
	-- Make a selection from the popupbutton.
	delay 2.501682
	set timeoutSeconds to 2.0
	set uiScript to "click pop up button 2 of group 2 of window \"Signatures\" of application process \"Outlook\""
	-- Initial
	delay 2.907227
	set timeoutSeconds to 2.0
	set uiScript to "click menu item \"Initial\" of menu 1 of pop up button 2 of group 2 of window \"Signatures\" of application process \"Outlook\"" -- Click the “<fill in title>” button.
	delay 2.753081
	set timeoutSeconds to 2.0
	set uiScript to "click UI Element 6 of window \"Signatures\" of application process \"Outlook\""
	-- Click the “<fill in title>” button.
	delay 3.181632
	set timeoutSeconds to 2.0
	set uiScript to "click UI Element 5 of window 1 of application process \"Outlook\""
	-- Click the “<fill in title>” button.
	delay 1.879827
	set timeoutSeconds to 2.0
	set uiScript to "click UI Element 19 of window \"Outlook Preferences\" of application process \"Outlook\""
end tell

For legibility, you can enclose code in fenced backtick triples, e.g.

```
tell application "Microsoft Outlook"
   
   activate
   
   set TheRecipient to the clipboard
   
   set theSubject to "leads!"
   
   set theSignatureName to "Initial"
   
   set newMessage to make new outgoing message with properties {subject:theSubject}
   
   set the message signature of newMessage to signature "Initial"
   
   make new recipient at newMessage with properties {email address:{address:TheRecipient}}
   
   delay 5
   
   #send newMessage
   
end tell
```

Thanks for the clarification on that part - im trying to figure out the GUI syntax to select the buttons:

Screen Shot 2021-01-02 at 1.08.10 PM

Chances of getting help will probably improve if you can edit that first post and make it legible.

At the moment it imposes discouraging effort on the potential reader.

  • Pencil icon to edit
  • 'code fencing' backtick triples at start and end of code.
  • Remove the bolding asterisks to allow syntax recognition and highlighting
  • Save

ok I think I was able to fix the formatting with your suggestion, for people to better read/see it.

1 Like

Hey Cory,

Welcome to the forum!   :smile:

From your description it's unclear to me what you're trying to do...

It looks to me like you're just creating a new message and select a given signature.

Signatures are available in the Drafts menu, so you don't need to fool with scripting the ribbon.

They are also pretty scriptable – at least in Outlook 16.16.10.

If you're most specific about what you're doing we'll have a better idea of how to help.

-Chris

So when I created my different automator / applescript functions it does NOT work in Outlook to create a new email using the signature block I want it to with the email address I want it to send from.

The Outlook part of the script should:

Create New email using account X not Y

Then select the Signature Name (Initial)

Compose New Email

Wait for the signature to compose in the new email.

Autofill the subject with content (XYZ)

Paste the content from the clipboard in the To: section of the email.

Send Email

Create a new Email and repeat the process, basically.

Hope this is more clear.

image