I have been searching all over the internet, forums, etc. to work out how to filter out folders by their name and rename / copy the remaining folder. In my example (that is most likely not even close to correct!) the user is asked to input a File Name and then the contents of the folder named Booking Files is filtered to remove folders that are named 360, Blue Skies, New, Watermark. The remaining folder (there will only ever be one) is then named with the File Name (that is declared as a variable) before being copied to the desktop.
I am attaching a screenshot of my Macros and would like to see how this type of thing is done without scripts so I can learn. Thank you in advance for any help
Prompt for User Input.kmmacros
You might want to change the
if condition to
does not match and use the following string:
You could also use the
copy action instead of move if you wanted.
Thank you very much for your help
Glad to help, don’t hesitate to reach out if you need more info!
In case you are still working on this, here is a slightly amended version of what you were doing.
Moving folders containing files around using Keyboard Maestro is potentially a bit risky as there is no undo...
So, the below has a couple of safety checks added. First it checks if the file is actually a folder rather than a file (by checking the file type is "Directory"). And secondly (even though you said there would only ever be one odd folder) it stops after moving and renaming one folder (by using a
Break from Loop Action).
Also, instead of using Matches 360|Blue Skies|New|Watermark (which would also match a folder called "360 test" or "360 Blue Skies" I used a list of "is not" tests. This can no doubt be done in Regex but that is beyond my Regex skill.
Move and Rename a Folder v2.00.kmmacros (6.2 KB)
Click to Show Image of Macro
Hi @Zabobon and @Margate. The If action could be changed as follows. (Some might argue, however, that this version is more difficult to interpret.)
Aside: By convention, I suggest entering an Intentionally Blank Comment action. Otherwise when coming back to a macro, one might wonder if the else case was left undone.
Hi @_jims that's great. I searched and couldn't find how to make the Regex only match exact matches in a multiple selection. So, the reason this works is that ^ says the start has to match and $ says the end of the phrase has to match, meaning in effect the whole phrase between each |?
You got it!
$ are line anchors.
^ means that the following character or string must be at the beginning of the line
$ means that the preceding character or string must be at the beginning of the line.
They’re very useful, especially if you’re iterating over a bunch of lines that have a similar format.
But I was incorrect,
is NOT equivalent to:
does not match
would be interpreted as:
local__name does not
Blue Skies or
I corrected my post above.
Also, I should have mentioned that matches is case-sensitive by default. To make it case-insensitive, one would need to use:
To reinforce that it's actually case-insensitive, I'd probably write it as:
...And if that wasn’t complicated enough... I would write it this way:
Chris, good point. I like that better (and have probably done it in a similar way):
I typically exclude the
?: prefix unless:
a. I'm using the Search and Replace action or the Search using Regular Expression action, AND
b. I want to define the group as non-capturing.
I exclude where I can, but my RegEx is typically rather complex and uses a variety of capture groups... so as a default I go to non-capturing groups just to help visualize things better.
One man's visual cue is another man's confusing syntax. And for me, it probably depends on the day of the week and the phase of the moon.
Seems like a good place for this xkcd.