Two Macro Questions From a New User

I'm testing Keyboard Maestro. I have created a macro whereby the End key will scroll to the last message in each Mail viewer window. One of the actions is an AppleScript that makes a list (a multi-line string) of the names of the open message viewer windows (e.g., "All Inboxes, All Sent, All Drafts") followed by regular KM actions to handle each of those viewers.

I hate AppleScript. I've been writing code for decades, but AppleScript confounds me terribly.

I'd like to replace this script with KM actions:

tell application "Mail"
   set messageViewers to ""
   repeat with theViewer in message viewers
      set messageViewers to messageViewers & name of theViewer & return
   end repeat
end tell

The variable "messageViewers" is the output -- a multi-line string.

  1. Is there a way to replace that AppleScript with KM actions?

  2. Assuming I have to use AppleScript, I'd prefer to use this which outputs a list:

tell application "Mail"
   set messageViewers to name of every message viewer
end tell

What KM action can I use to process a list from AppleScript (rather than a multi-line string, as above)?

(3. Is there a way to preview new posts?)

Jeff

Hey Jeff,

Welcome to the forum!   :smile:

You don't want to – it's more complicated. You have to get the window count and then iterate through them by index and save the name.

Keyboard Maestro doesn't know how to discriminate between Message Viewer windows and other windows either.

A simpler AppleScript:

set AppleScript's text item delimiters to linefeed
tell application "Mail" to set messageViewers to (get name of message viewers) as Unicode text
return messageViewers

Keyboard Maestro variables are all plain text, so you can't. KM doesn't grok AppleScript list objects.

What do you mean?

A post you're composing? Or ALL posts to the forum?

If the latter look at your forum email preferences.

I have mailing list mode turned on, so I get every message posted to the forum.

I sort them to a KM-Forum mailbox with a Mail rule and skip through them at my leisure.

I have a macro that takes me to any given email's related post on the forum, which I use if I'm interested in the thread and/or want to contribute.

I don't like composing message for the forum in Mail, because you can't tell for sure how the formatting will work out.

Appended is the simplest way (I think) to brute-force your task above with Keyboard Maestro.

-Chris


Scroll To End of Every Mail Viewer Window's Message List v1.00.kmmacros (9.3 KB)

Hey Jeff,

Personally I would not do this particular job with Keyboard Maestro actions; I'd use AppleScript UI-Scripting.

This task should be a piece of cake using AppleScript, but it's not – because AppleScript does not allow a means to account for the sort in message viewer windows.

Therefore we have to resort to UI-Scripting to get a more organic and controllable process than Keyboard Maestro's brute-forcing the UI approach.

This is not pretty and will tend to confound people unfamiliar with UI-Scripting, furthermore this script is for Apple Mail 10.3 on macOS 10.12.6 and will likely NOT work without adjustments on earlier or later versions of macOS.

Nevertheless – it's reasonably fast and doesn't require that each mail viewer window be made frontmost before taking the actions needed to select the last message.

Note – I'm not a huge fan of AppleScript either, but I've been using daily for 25 years – because it's so darn useful. If you're a fan of JavaScript then you might be interested in JXA (JavaScript for Automation).

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/03/31 01:12
# dMod: 2021/03/31 01:12 
# Appl: Mail, System Events
# Task: Select the Last Item in the Message List of Each Message Viewer window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events, @Select, @Message, @Mail_Viewer
# Test: Tested only on macOS 10.12.6
--------------------------------------------------------

tell application "Mail"
   set mvWindowNameList to name of message viewers
end tell

repeat with mvWindowName in mvWindowNameList
   
   tell application "System Events"
      tell application "System Events"
         tell application process "Mail"
            tell (first window whose subrole is "AXStandardWindow" and name is mvWindowName)
               tell splitter group 1
                  tell splitter group 1
                     tell group 1
                        tell scroll area 1
                           
                           tell scroll bar 1
                              if value ≠ 1.0 then set value to 1.0
                           end tell
                           
                           tell table 1
                              
                              if focused is false then set focused to true
                              set lastRow to count of rows
                              
                              tell row lastRow
                                 set selected to true
                              end tell
                              
                           end tell
                           
                        end tell
                     end tell
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
   
end repeat

--------------------------------------------------------

I mean how can I preview a question (or reply) that I'm about to post to the forum? Now I see the live preview to the right of the markup area. That was hidden under the large yellow block of advisory text that's shown to new users like me for the first two posts. Now I see the preview! What a relief.

Thank you for your macro suggestions. I don't think your last three keystroke actions do what I want. Here's the working Global Macro macro I have designed:

image

The two Play Sound actions warn me that the macro is working.

That's a heap of AppleScript. But, as I said, I hate AppleScrirpt so it's painful to look at. :blush: I'll use KM actions as much as I can (see my other reply).

That yellow block ("Welcome to Keyboard Maestro Discourse") is covering the live preview area again. If I dismiss it, I see the preview.

It should respond to the Escape key.

When I post a macro, how do I include the trigger section (like you did and I did not)?

Hey Jeff,

See this:

How to Post Your Macro to the Forum

Holler if you have an more questions.

-Chris