Is it possible to select a smart list in Mail?
Hey Ali,
You mean a smart-mailbox?
Not with AppleScript.
Mail does NOT recognize smart-mailboxes as objects to be worked with.
You can work around this in a few ways:
A) Add the smart-mailbox to your favorite mailbox toolbar, so it can be accessed via menu item or keyboard shortcut. (Unfortunately this method limits you to 9 items.)
B) Use UI-Scripting to do it.
This script assumes:
- You're using the classic view in mail.
- The mailbox panel is OPEN.
- The Smart-Mailbox list is NOT hidden.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/03 19:00
# dMod: 2017/11/03 19:13
# Appl: Mail
# Task: Select a Smart-Mailbox by Row Number.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events, @Select, @Smart-Mailbox, @Row, @Number
------------------------------------------------------------------------------
set smartMailboxRowNumber to 19
tell application "System Events"
tell application process "Mail"
tell front window
tell splitter group 1
tell scroll area 1
tell outline 1
tell row smartMailboxRowNumber
set value of attribute "AXSelected" to true
end tell
end tell
end tell
end tell
end tell
end tell
end tell
------------------------------------------------------------------------------
While it is possible to use the name of a Smart-Mailbox rather than its row-number, it is MUCH faster to use the row-number.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/03 19:00
# dMod: 2017/11/03 19:30
# Appl: Mail
# Task: Select a Smart-Mailbox by Name.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events, @Select, @Smart-Mailbox, @Name
------------------------------------------------------------------------------
set smartMailboxName to "Keyboard Maestro"
tell application "System Events"
tell application process "Mail"
tell (first window whose subrole is "AXStandardWindow")
tell splitter group 1
tell scroll area 1
tell outline 1
tell (first row where its UI element 1's text field 1's value is smartMailboxName)
set value of attribute "AXSelected" to true
end tell
end tell
end tell
end tell
end tell
end tell
end tell
------------------------------------------------------------------------------
This method works fine but is substantially slower than selecting-by-row-number.
I did some testing and it is possible to select the last message in the message list.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/04 05:00
# dMod: 2017/11/04 05:28
# Appl: Mail
# Task: Select the last message in the message list.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events
# Task: Select the last message in the message list.
------------------------------------------------------------------------------
tell application "System Events"
tell application process "Mail"
tell (first window whose subrole is "AXStandardWindow")
tell splitter group 1
tell splitter group 1
tell group 1
tell scroll area 1
set focused to true
tell scroll bar 1
set value of attribute "AXValue" to 2000
end tell
tell table 1
set lastRow to count of rows
tell row lastRow
tell attribute "AXSelected"
set value to true
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
------------------------------------------------------------------------------
-Chris