One of the pesky issues with Mail is differentiating between mail-viewer-windows and message-windows.
Since System Events has gotten faster and more reliable I've been willing to use it more, and in this case I used it to find only message windows.
You have to have the 'Get Mail' button in your message-viewer toolbar for this to work, and I'm not taking into account any localization.
------------------------------------------------------------------------------------------- # Written for someone on another list. ------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2015/10/18 22:20 # dMod: 2015/10/18 22:39 # Appl: Mail, System Events # Task: Close Message Windows using a Pick-List. # Libs: None # Osax: None # Tags: @Applescript, @Script, @Mail, @System_Events -------------------------------------------------------------------------------------------
tell application "System Events" tell application process "Mail" set winList to windows set messageWinNameList to {} repeat with i in winList if not (exists of button "Get Mail" of toolbar 1 of i) then set end of messageWinNameList to name of i end if end repeat end tell end tell
-------------------------------------------------------------------------------------------
tell application "Mail" set closeWinList to choose from list messageWinNameList with title "MESSAGE WINDOWS" with prompt ¬ "Choose which windows to close:" default items {item 1 of messageWinNameList} ¬ with multiple selections allowed try repeat with i in closeWinList close window i end repeat end try end tell
-------------------------------------------------------------------------------------------
Okay, playing with it this evening:
------------------------------------------------------------------------------------------- tell application "System Events" tell application process "Mail" set winList to windows where (name of buttons of its toolbar 1) does not contain "Get Mail" end tell end tell -------------------------------------------------------------------------------------------
Still not discriminating between received and outgoing messages, but it's a start.
|