Regex like search in action: If at path something exists? in a Folder containing ~1000 image files

Thanks for sharing that tip

I would get away from using the tilde—it's a shorthand that requires the shell know the path to your home folder. Instead, just use the full path, which for a macOS user, will always be (unless they've relocated their Home folder, which is quite rare):


Then you can put double quotes around the whole thing.


1 Like

The reason I always avoid full paths is because if I buy a new computer (or just reinstall the macOS) and for some reason I don't want to keep the same name for my User folder, all my macros will still work.

So if I keep the tilde, should the single quote come right after it?
Or for example if I use it like this, will it still work, since the spaces are not in the beginning?
~/folder1/folder2/'folder 3/file.png'

It's not that I will be doing it, because it makes everything more confusing. I'm just wondering if that would also work.
Whenever I need to use something like that, I will definitely do ~'

No, as long as the spaces are enclosed. But probably easiest to put immediately after the ~.

Another option is to not use quotes; instead escape the spaces with backslashes (\). For example:

~/My\ Files/Tests/Keyboard\ Maestro\ Tests/RegEx\ in\ paths

FYI, one thing you can do is drag a folder from the Finder into a Terminal window. If the path has any spaces they will be automatically escaped. You can even start a command in Terminal (e.g., pwd followed by a space) then drag the folder into the Terminal window.

As long as the shell knows the path to home, that will work. And whether using single or double quotes, leave the tilde outside of it, as it won't be expanded if inside either type.

And really, use double quotes :).


Exactly. I was just curious if that was "a thing" :wink: Thanks for clarifying

This is always a very confusing option for me, especially when you have long paths and lots of spaces, which is pretty common with my folders and files.

Yes, when I use Terminal, that's what I do. I sometimes forget about that and I'm just working on a script using TextEdit or Notes, just because it's easier to click somewhere and edit it right away, and then the path is not properly "formatted". I wish the Terminal was a bit more flexible when it comes to editing stuff. Like a normal text editor where we can click somewhere and type, or select some text and delete it, etc.

I don't use it often anyway, but I think it would be way more pleasant to work with. Or at least, make it an option so those who like it the way it is, could keep it that way.

1 Like