dipping my toes into AppleScript using outlook…cant get a basic go to folder work
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:
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”.
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…
anyone know how to adjust my script to jump to the all accounts folders?
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
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.
@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