KeyboardMaestro: Regular Expressions when copying files

I’m trying to use a shell-style regular expression to copy a bunch of images from a memory card. Specifically, the bash/zsh command is “cp /Volumes/Untitled/DCIM/1*/*.JPG .”

I’m trying to do this in KeyboardMaestro, but the Copy File box does not allow me to do that. Do I need to form my regular expression differently? Or do I need to loop through the files and copy them one at a time?

Any help would be much appreciated.

While unfamiliar with the “Copy File box”, I guess that you should run your regex line in a “Run shell script” block in KM.

1 Like

If you have a working script, why not just run that from Keyboard Maestro?

1 Like

I’m not sure what the answer is, but you might want to ask on the Keyboard Maestro Discourse where you’ll find more Keyboard Maestro-specific-knowledge (and also the Keyboard Maestro developer, from time-to-time).

1 Like

The reason it doesn’t allow for wild card matches is because the macro action is designed to be for a single file only and any wild card match could always match multiple files. The name isn’t copy files after all.

To work with groups you would probably want to build a collection of matching file paths and then move each file specified by its path in the collection.

That is all much more work than just using a shell script and having that executed from within Keyboard Maestro. As far as I can tell, because there are no additional actions, there seems no fundamental reason not to use the shell script.

1 Like

Fair ask. I’d like to parameterize the script as to have a dialog box first to enter a folder name and then use that throughout the script. The problem with bash is that if you have spaces in folder or file names, formulating the correct regex gets extremely tough depending whether regex is part of the script itself or in variables. Some of the stack overflow discussions around that blow your mind. zsh is supposed to be better at that, but I don’t know it (and the read parameters from bash do not seem to work). That may be the way to go.
I could launch the script from Keyboard Maestro, but I keep running into permission issues and don’t want to hard-code my superuser password into a script.
It find it frustrating that I can type (or use text expander) four or five shell commands more quickly than spending all this time to automate these 4-5 shell commands.

If you can build the script with an example path in it, then you should just be able to capture the optional part into a Keyboard Maestro variable via a dialog, and drop it into the script as per the examples in the Execute a Shell Script documentation.

You could standardise on either option using a Keyboard Maestro variable. Either repeat it throughout for direct insertion, or set an in-script variable once.

Pressumably then you have something in mind that is more complex than the example you started with then?

That’s odd. Keyboard Maestro should be running with your user account permissions for executing scripts. Definitely not a path issue (note: Keyboard Maestro doesn’t load in your standard profile configurations by default)?