You need to enclose the search expression with ` in the post or use the escape backslash \, otherwise, the two * are taken to be a Markdown italic code. I thought you missed the * until I quote it.
When posting macros to the Keyboard Maestro forum please use these guidelines:
Always post a Macro File.
Always post an image.
This means people won't have to reinvent the wheel to test your macro, and that significantly improves the likelihood that someone will help you.
Also a good rule-of-the-thumb is β βIf you're not testing you're guessing.β β and guessing quite often wastes a lot of everyone's valuable time.
The same often holds true of written descriptions of problems. They tend to leave out crucial details.
Folks generally won't download something they haven't eyeballed first, so an image of the macro is crucial.
If you haven't seen these they're worth a moment of your time:
Never use %VariableName% as a variable notation, while it's legal it should NOT be β because it's the same as KM's text-token notation. If you use it then you can't tell at a glance the difference between Tokenized-Variable-Names and actual Text-Tokens.
RegEx101.com is a great resource, but there are some subtle differences between the regex variants they make available and the ICU regular expression set Keyboard Maestro uses.
You must also pay close attention to the RegEx Flags that have been set.
Note that myfile.txt contains a regex metacharacter that needs to be escaped.
Note that this pattern ^.*myfile.txt.*$ is potentially dangerous β it can accidentally match any string in the path β not just the file name.
Note that multiline is NOT on by default in Keyboard Maestro, so when you're anchoring to the start of a line (not the entire string) you need to turn it ON.
(?m)<your-regex>
To clarify β all code posted to the forum should be properly fenced.
You can use the Pre-Formatted Text button in the forum editor:
It just occurred to me, if your purpose is to get the path that contains your file, then the best way is probably not to use RegEx, because your file name may contain characters that have special meaning in RegEx.
In the example above, because the file name contains brackets and - inside the brackets, it has special meaning in RegEx. A RegEx search will not find what we want. But the if variable contains the filename returns true.
If you want to get the full path that contains your file name, then you can loop through the text, like this:
Thanks for pointing that out. I did not look carefully enough.
Yes. That was my thought too.
I was thinking of either adding a break from loop action or a cancel this macro action to the macro, depending whether @freewind1974 needs a multiple match or what else he wants to do with the match result.
I got lost following the conversation, so I better explain what I wanted to achieve and how I did it.
It's a bit hard for me to share the macros right now... I'll try my best to explain them.
I mix and master records in Pro Tools.
I built a lot of macros inside PT: recently, I wanted to get a more intuitive (for me personally) Open Session function.
Instead of getting a "recent files" list, with very long paths (on different drives) and the session names at the end (that is, difficult to read), I thought of using a "Prompt with list" window, with just the session names (in alphabetical order), filter them the way I want (for example, typing "MIX" I get only the mixing sessions, "MST" for mastering sessions, and so on), associate the corresponding path and open the session automatically.
I jump between sessions much quicker this way.
So, in order to keep track of the sessions I progressively open, I did this:
When PT's "focused window title changes", I get the session path + name from PT's Edit Window, if at the front;
I have a couple variables, one with full session paths + names, the other with session names only. The order of course is the same.
The entries for both variables are separated by %Return% and I already was adding a "/" on top of the path before writing here.
If the current session is not already contained in the variables, it gets added;
When closing PT, those variables are saved into txt files, and reloaded when PT reopens.
A separate macro deletes all history (files + variables) when needed.
With Option+O (my Open macro), I get prompted with the list of session names, alphabetically ordered. Then I got stuck about using RegEx with variables, and came here.
I couldn't make @martin suggestions work; I adapted @ccstone solution and it worked perfectly.
The path gets correctly associated.
Furthermore, once I open Pro Tools Finder with Cmd-O (regular Open Session PT command):
I paste the complete session name with Shift-Cmd-G;
What we were talking is mainly about RegEx. As I said, when you have a variable in a RegEx search, make sure you understand you are searching for literal characters or you want some special characters to be interpreted by RegEx. In your case, you need to search for literal strings. @ccstone has done this for you by adding an escape character to the variable string. Other wise, a dot . in RegEx matches any character (except for line terminators). For instance, myfile.txt will not only match /path/to/myfile.txt, it will also match /path/to/myfile$txt, /path/to/myfileAtxt, /path/to/myfile-txt, etc.
From what I understand about your purpose, I think, with some modifications, the macro below should work for you.
See screenshot below for instructions.
To ensure the hot key is sent to your desired app, Pro Tools, it is better to use the "Send To" option. I don't have PT. So I set it to Finder. You may change it to PT. In a series of keystrokes, adding pauses might be necessary in many cases. I added an example for you.
The slash / in the "end with" condition is needed. Otherwise, myfile.txt will match /path/to/myfile.txt and /path/to/anycharactersmyfile.txt.