I’m a long time owner (just upgraded to V8) though I rarely actually use it so I struggle sometimes to figure out how to write a script given the dictionary.
Right now I’m trying to create (what I thought would be) a trivial script to change the sort view of AppleMail from Date Received to From and so forth but I’m having zero luck getting this to work.
I did however notice that having written
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Mail"
activate
set viewer to the front message viewer
set sort column of viewer to from column -- this fails
end tell
I see numerous errors (see screenshot) that seem related to accessing the columns but I have no idea what to do.
Suggestions would be very much appreciated. I’m running Mail on Big Sur
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/04 00:29
# dMod: 2021/08/01 18:09
# Appl: Mail
# Task: Sort Messages on From-Column { toggle ascending/descending }.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @Set, @Sort, @Column, @Date, @Sent
# Test: macOS 10.12.6 Sierra through macOS 10.14.6 Mojave
# Vers: 1.00
--------------------------------------------------------
tell application "Mail"
tell (some message viewer whose index is 1)
if sort column = from column then
set sorted ascending to not (get sorted ascending)
else
set sort column to from column
set sorted ascending to true
end if
end tell
end tell
--------------------------------------------------------
The appended script works with Mail (Mojave) but may require tweaking for other versions of macOS.
On my system it’s a little sluggish activating “Oldest Messages on Top”, but it works – and it will toggle between Oldest and Newest if Date is already selected as the sort.
Keyboard Maestro is another option. It runs AppleScript slower than FastScripts, but then again you don’t have to write AppleScript to work with (most) menu items.
-Chris
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/08/04 09:56
# dMod: 2021/08/04 09:56
# Appl: Mail
# Task: Sort by Date ⇢ Oldest Message on Top (Toggle).
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events, @Sort, @Messages
--------------------------------------------------------
tell application "System Events"
tell application process "Mail"
tell menu bar 1
tell menu bar item "View"
# perform action "AXPress"
tell menu 1
tell menu item "Sort By"
# perform action "AXPress"
tell menu 1
tell menu item "Date"
perform action "AXPress"
# if value of attribute "AXMenuItemMarkChar" ≠ "✓" then
# perform action "AXPress"
# end if
end tell
repeat until exists of menu item "Oldest Message on Top"
delay 0.05
end repeat
tell menu item "Oldest Message on Top"
if value of attribute "AXMenuItemMarkChar" ≠ "✓" then
perform action "AXPress"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
--------------------------------------------------------
Yeah, I had already noticed Script Debugger was not in the list but even after rebooting and trying the script again, I was not prompted to add it to the Automation menu. There doesn’t seem to be a(n easy) way to manually add an item to that menu.