Controlling Microsoft Outlook's "go to" command (Asked and answered)

I much prefer the way that the Calendar app prints weekly calendars to the output from Microsoft Outlook. I have written a script that exports events from Outlook into Calendar by iterating through the days of the week, creating an ics file for each event, and importing each ics file into Calendar. This works, but I’d like to not disturb the existing windows in Outlook, at least the not the ones that aren’t calendar views. My current approach is to see if there is an open main window with a calendar view and make it front most. However, when I use the “go to” command, it seems to choose randomly any of the main windows, changes it to the calendar view, and then goes to the specified date.

In the course of making a smaller test case to demonstrate the issue, I of course found the answer. The key was to use System Event’s perform action “AxRaise”.


set yesterday to (current date) - 1 * days
set calWindow to my findCalWin()
get properties of calWindow
tell application "Microsoft Outlook"
	activate
	tell application "System Events"
		set MO to application process "Microsoft Outlook"
		tell MO
			set seCalWin to window "Calendar"
			perform action "AXRaise" of seCalWin
		end tell
	end tell
	tell window calWindow
		go to yesterday
	end tell
end tell

on findCalWin()
	local calWins
	tell application "Microsoft Outlook"
		set calWins to main windows whose view is equal to calendar view
	end tell
	return first item of calWins
end findCalWin