My Outlook 2011 Macros

Hey Jaco,

This should be a simple task, but at least for Microsoft Outlook 2016 it's not (as far as I can tell)...

It should be easily possible to add, subtract, or change to-recipients, but my old code for Microsoft Outlook 2011 doesn't work – hence this work-around.

It's tested with Microsoft Outlook 16.16.27 on macOS 10.14.6 and may require adjusting for different versions of Outlook or macOS.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/15 17:00
# dMod: 2022/01/12 11:24
# Appl: Microsoft Outlook, System Events
# Task: Set To-Field of front draft window to email address 1 if more than 1.
# Tags: @Applescript, @Script, @Microsoft_Outlook, @System_Events, @KMF
# Test: Tested only with Microsoft Outlook 16.16.27 on macOS 10.14.6.
--------------------------------------------------------

tell application "Microsoft Outlook"
   if class of front window ≠ draft window then
      error "Front window is not a draft window!"
   else
      tell front draft window
         if its object = missing value then save
         set recipientList to its object's to recipients
         if length of recipientList > 1 then
            set recipientOne to item 1 of recipientList
            set recipientOneEmailAddress to address of (get email address of recipientOne)
         end if
      end tell
   end if
end tell

--------------------------------------------------------

tell application "System Events"
   if quit delay ≠ 0 then set quit delay to 0
   
   tell application process "Microsoft Outlook"
      tell (first window whose subrole is "AXStandardWindow")
         
         tell splitter group 1
            
            tell (first scroll area whose accessibility description is "To:")
               tell text area 1
                  # set toFieldFocus to its focused
                  set its value to recipientOneEmailAddress
               end tell
            end tell
            
            # Unnecessary code I left in as an example
            # if toFieldFocus then
            # 	tell (first text field whose accessibility description is "Subject:")
            # 		set its focused to true
            # 	end tell
            # end if
            
         end tell
         
      end tell
   end tell
   
end tell

--------------------------------------------------------

-Chris