b) Earlier and later actions include the below two which work consistently and flawlessly, where %MailCCRecipients% and %MailSender% are also macOS Mail tokens.
Why do %MailCCRecipients% and %MailSender% work flawlessly while %MailRawSource% does not, noting the action / assignment is the same in all three?
Even if the first "Display" is blank, does it consistently show the raw contents in the second?
I'm wondering if you've a slow connection to your mail server, and the token is timing out when trying to retrieve uncached raw contents -- recipients and sender will be downloaded as Mail updates the mailbox, but email contents are often left for later or until needed.
(I think, but don't know, that a timed-out token will return an empty string rather than erroring out your macro. Anyone?)
Since it sounds like it's not a headers-only issue, another reason I can think of that covers both of these symptoms is that you're losing the mail selection for some reason. Or, if the "Forward" always works and it's only "Reply" and "Reply All" that are failing you might have multiple messages selected, potentially exceeding the amount of dat that can be returned by the %MailRawSource% Token.
The submacros are missing from your upload, but they don't get called until after the failing Token so I don't think they'll be the cause.
Since everything's working as expected in my tests (Mail in macOS 26.1, using both Exchange and standard IMAP accounts) I reckon @griffman's right -- you'll have to troubleshoot this yourself, stepping through the macro with the Debugger so you can see exactly what's going on.
If I leave that action enabled and place the Message > Reply action above it then the Reply message appears. It works.
If I leave the action enabled and place the Message > Reply action below it then the Reply message fails. It does not work!
If I disable the Display Text box as I currently have then the macro fires reliably, without issue!
So, the question I have for @Nige_S , @griffman, @peternlewis and others is simple, what problem is being caused by the Display Text action that it is responsible for i) the %MailRawSource% token not being received and the Message > Reply / Reply All / Forward not firing?
I will for now leave the Display Text action disabled but I would love to know what the problem and solution are.
Look forward ti your assistance, feedback and ultimately a solution!!
I don't know why technically, but what happens is that the Display Text window blocks the ability of Keyboard Maestro to "see" what's in the Mail window. If you add a long enough pause for you to click the OK button to dismiss the window before the Mail menu command runs, it should work.
As a longer term solution, use a Notification or write the value to a text file, etc. Or just use the debugger when needed.
Why does the Raw Data fail to load? Is it the same reason, loss of focus?
Why does the problem only occur with the Display Text window for the %MailRawData% token but none of the other Display Text windows?
Would it be correct to conclude based on the above that when testing macros Display Text windows are not ideal because they can take away focus and impede a macro’s functionality? What is the preferred Display Text format for debugging?
Yes. I would probably append to a log file, and then display that, either with tail -f in the Terminal, with the Console, or BBEdit.
MailRawSource is simply AppleScript for:
tell application "Mail"
set r to ""
if it is running then
try
set s to the selection
set m to first item of s
set r to (source of m) as string
end try
end if
r
end tell
What you get back is what Keyboard Maestro gives you for the token.
No idea, that is two specific a case for me to have any idea what is happening.
There's a lack of version info in your posts (or I'm just not seeing it!) but the things you're having trouble with all work fine in macOS 26.1 -- %MailRawSource% doesn't need Mail to be the frontmost app and your "Select Menu" Action should work fine because you've specifically targeted Mail.
I still think there's something going here on that's specific to your setup...
Try stepping through in the Debugger again, but pay less attention to the Debugger and KM variables and more to what happens with Mail itself, particularly on whether email remains selected during those parts of the macro.
I am running macOS 26.2 on an Apple M4 MacBook Pro.
I noticed that the Display Text windows (i.e., any Display Text window) takes the focus away from the Mail specific e-mail (i.e., when I execute the macro, the selected e-mail is highlighted in blue but when the Display Text box appears, the selected e-mail is highlighted in grey [focus is lost]).
I played with it some more and noticed that each and every Display Text box placed before the Messages > Reply / Reply All / Forward caused the same behaviour. It is not related to the %MailRawContents% token but to the Display Text Box.
I think that while the reference to Mail in the Select Mail is correct as you note that one also needs to have an e-mail selected which is not the case because of the loss of focus and why we are seeing this behaviour in Mail (and not elsewhere) (i.e., it is specific to needing an e-mail selected).
Not quite. It takes "input focus" away from Mail -- keystrokes are directed at the "Display Text" window -- but Mail remains the frontmost app. Importantly, the selected email remains selected in Mail, which is what's needed for both the Token and the menu manipulation.
Mail does not need to be the frontmost app and does not need "input focus" for the %MailRawSource% Token to be evaluated
Mail does not need to be the frontmost app for a targeted (rather than "Select menu in Front Application") "Select or Show a Manu Item" Action to work
In the KM Editor (so KM is the frontmost app) try "View"ing the "Display Text" Action
In short -- I can't reproduce the issue here so it looks to be something specific to your macro and/or setup rather than a general KM/Mail problem.
As usual, you really need to write and then post the most minimal macro that will demonstrate the issue. Nine times out of ten just writing a new demo macro and the explanatory post will lead to a face-palm moment when you realise what you were/won't doing in your main macro that caused the problem -- what's known as "Rubber Ducking".
Hardly the "minimum macro to demonstrate the problem".
But if I re-enable the "Display Text"s and put a "Cancel This Macro" after displaying the reformatted date, the macro works fine for me whether or not the selected email has someone CCed -- the presence or absence of a "Display Text" makes no difference to the %MailRawSource% Token.
For the future, don't forget you can use Tokens directly in many places -- you don't have to set to a variable first. So: