Hi Peter and Keyboard Maestro Community,
I'm running into a puzzling issue with a "Search Variable Using Regular Expression" action in Keyboard Maestro 11.0.3 on macOS.
I'm trying to read lines from a plain text UTF-8 file (e.g., Ticker,CompanyName
) and split each line into two variables (Local_Ticker
and Local_Name
) using the regex ^([^,]+),(.*)$
.
The issue is that the regex ^([^,]+),(.*)$
works perfectly with my test data (e.g., NYSE:A,Agilent Technologies, Inc. - $A
) when tested on regex101.com (ECMAScript flavor), correctly identifying Group 1 and Group 2.
However, in my Keyboard Maestro macro, while the "For Each" loop successfully reads the line into a Local Site
variable (confirmed by a Display Text in Window
action), the subsequent "Search Variable Local Site
Using Regular Expression" action results in empty Local_Ticker
and Local_Name
variables.
Critically, even with "Failure Aborts Macro" OFF and "Notify on Failure" ON in the "Search Variable..." action, I do not receive any notification from Keyboard Maestro that the regex failed to match. The macro proceeds to the next action, but the capture group variables are empty.
What I've Confirmed/Tried:
- Basic Macro Execution:
- The macro trigger works.
- The Keyboard Maestro Engine is running.
- The Macro Group is active and enabled ("Available in all applications" for testing).
- A
Beep
action as the very first action in the macro works. - A
Display Text "static text" in Window
action as the second action (before the loop) works. - A
Display Text "static text" Briefly
action as the second action does NOT work (no window appears, though the beep before it works). This might be a separate minor issue or related.
- File Reading:
- The
For Each Local Site in The lines in: File "/path/to/my/file.txt"
action successfully reads the first line intoLocal Site
. This is confirmed by aDisplay Text "%Variable%Local Site%" in Window
action immediately inside the loop, which shows the correct line content. - Initially, I had "Assertion Failed" errors in the Engine.log (
CLinesInCollection.mm
andLinesIn.mm
). These errors seem to have been resolved by deleting the original input file and recreating it from scratch as a plain text, UTF-8 encoded file using TextEdit (Format > Make Plain Text
, then save as UTF-8). The loop now proceeds to read the first line. - I have granted Keyboard Maestro Engine "Full Disk Access."
- The input file currently contains simple, known-good data like
NYSE:A,Agilent Technologies, Inc. - $A
or even justFff,ddd
.
- Regex Action and Variable Display:
- The regex pattern in KM is
^([^,]+),(.*)$
(typed carefully, no smart quotes/spaces). - "Search Variable
Local Site
Using Regular Expression" settings:- Search
Local Site
. - Regex
^([^,]+),(.*)$
. - Save All to
Local Site
(or a test variable). - Save Group 1 to
Local_Ticker
. - Save Group 2 to
Local_Name
. - "Failure Aborts Macro": OFF.
- "Notify on Failure": ON.
- Search
- An immediately following
Display Text in Window
action showsLocal Site
correctly, butLocal_Ticker
andLocal_Name
are empty. - No "Regex failed to match" notification appears from KM.
- Data Cleaning:
- I've added actions to
Trim Whitespace variable Local Site from leading and trailing
before the regex action. - I've also added
Search and Replace Variable "Local Site"
(searching for\r\n?|\n|\r
and replacing with empty) before the regex action to remove any potential embedded newlines. - These cleaning steps did not change the outcome (capture groups remain empty, no failure notification).
- System:
- Keyboard Maestro Version: 11.0.3 (from Engine.log)
- macOS Version: [Please add your macOS version here, e.g., "Sonoma 14.4.1"]
- I have restarted the Mac multiple times.
My main question is: Why would the regex capture groups be empty in Keyboard Maestro if the regex itself is valid for the data (as proven on regex101.com), the input variable Local Site
appears correct, and Keyboard Maestro is not even reporting a match failure? It seems like the match might be succeeding internally in some way that doesn't throw an error, but the capture group assignment is failing.
Any insights or further diagnostic steps would be greatly appreciated. This has been quite a puzzle!
Thank you,