Outlook AppleScript to go to all account inbox

Hi all

dipping my toes into AppleScript using outlook…cant get a basic go to folder work :slight_smile:

I have gotten so far as being able to go to exchange folders via this:

tell application "Microsoft Outlook"
	activate
	set theFolder to mail folder "Sent Items" of exchange account "XXX@YYY.coml"
	set selected folder to theFolder
end tell

but that doesn’t work in any gmail accounts…

what I simply want is to go to the inbox/sent/drafts etc of the allacounts folders, ie:

CleanShot 2024-03-17 at 11.37.02@2x

any clue anyone?

thanks so much in advance

Z

Have you tried “Sent” instead of “Sent Items”? Unfortunately, the Sent mailbox can have different names. Also, the mailboxes from Gmail are localized so that my Sent mailbox from Gmail is “Gesendet”.

thx alot @bwill !

I actually just figured this out this morning using coder ID , here is the script in case anyone is interested

tell application "Microsoft Outlook"
	activate
	set theFolder to mail folder id 199
	set selected folder to theFolder
end tell

but what is most important to me and I cant for the life if me figure it out is how to get to the all accounts folders such as inbox, sent etc. they dont seem to have a folder id… :frowning:

anyone know how to adjust my script to jump to the all accounts folders?

thx so much in advance!

Z

1 Like

Very good. The All Accounts mailbox doesn’t exist.

thx! so there is no way to use AppleScript to jump to any of the all accounts folders? bummer :frowning:

thx so much for your kind help @bwill !

Z

I don’t think that they are actually folders. They are window views that display the contents of (potentially) multiple folders.

thx @Mockman !

understood, so in that case anyone know of how to jump to a window view in outlook rather than a folder?

best

Z

You would have to use GUI scripting.
Also are you using Legacy Outlook, or new Outlook interface?

try this…

tell application "System Events"
	tell application process "Outlook"
		set frontmost to true
		tell (UI element 1 of UI element 1 of row 1 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 whose role is "AXDisclosureTriangle")
			if value = 0 then click
		end tell
		tell (row 2 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1)
			set value of attribute "AXSelected" to true
		end tell
	end tell
end tell

thx @robertfern , really appreciated!

Im using the legacy version, I tried running this in the script editor and get an error: window 1 of application process "Outlook", any clue?

best

Z

It says the error is “Script Debugger is not allowed assistive access”

It’s a permission issue. You have to give script debugger assistive access in your System Preferences.

Go to Privacy & Security, choose Accessibility.
Add Script Debugger

amazing!!! thank you so much @robertfern all!

what a great community to join :slight_smile:

best

Z

I was trying to do this a long while ago and gave up trying to identify the correct cascade of different UI elements for different folders. I ended up giving up and using Keyboard Maestro’s find image to do it, but that’s a bit finicky.

How do you (easily?) come up with the nested UI element tree to plug into the System Events commands?

I use a utility called “Accessibility Inspector” which is part of Apples Xcode development environment.

I’m using a slightly older version (version 4.1) that can be run as a standalone App without having to install Xcode. The newer versions will only run if the full Xcode is installed as it references libraries and frameworks that are part of the full package.

1 Like

wow @robertfern

very cool!

I tried using it:

yet im confused how/where do you get the correct cascade order?

thx again!

Z

1 Like

Not sure. I’m using an older version 4.1
The interface is quite different

gotcha @robertfern , so perhaps then I can ask in your amazing code to go to sent instead of inbox. ie:

CleanShot 2024-03-23 at 10.44.51@2x

is it a matter of changing a number in the code (which I can play around one by one :)) or is it more complex than that?

thx so much again!

Z

@zeltak
In the image in post 14, scroll down on the right (to below ‘Advanced’). Typically, near the bottom of the window is where you would find the hierarchy of elements. That said, apple seems to revise the interface with every os release.

Yes, you would change the number of the row from 2 to 4 like the line below…

tell (row 4 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1)

or you can have the item be found by name like so…

tell application "System Events"
	tell application process "Outlook"
		set frontmost to true
		tell (UI element 1 of UI element 1 of row 1 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 whose role is "AXDisclosureTriangle")
			if value = 0 then click
		end tell
		tell (row 1 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 whose name of UI element 1 is "Sent")
			set value of attribute "AXSelected" to true
		end tell
	end tell
end tell
1 Like

amazing!!

thanks so much guys, truly appreciated!

Z