A while ago, @noisneil shared a macro to find Logic Patches and using an altered version of his macro I was able to find all .md files inside Obsidian by using this shell script:
How would I be able to change this to find folders, instead of files?
EDIT: I think I found it. Can someone confirm this is the right way to do it?
find "$KMVAR_Local__FolderPath" -type d;
This seems to be working, but when I use it with the Prompt With List action, I see the full path and I just wanted it to show the folder's name. I tried different option inside the Filter action, but can't seem to find a solution
Feel free to share that. Always good to learn something new and to make macros as short as possible
I just found this script somewhere and since I'm not familiar with it, that's all I could do with it.
Yeah, that's too complex for my level (or lack thereof) of shell script knowledge...
Somewhere in there is probably something that says "cut everything all the way up to the last / but I wouldn't be able to understand it at all...
Ok I think I'm getting there from doing some research...
You reverse the whole path, then you cut one of the "columns" (the f1) then reverse it again, etc...
But can't really see how you achieve it. I would need a few more minutes
It's not that bad. You wanted just the basename. So the first thing I did was reverse ("rev") the contents of every line. Then I removed (with "cut") every "field" past the first "/" (since the lines are reversed, that means remove everything up to the last "/" inclusive), then I reversed the lines again ("rev") and like magic you get the basename of each path.
Yeah, as long as it works... (even though, technically, I had some help from Neil and his macro).
But it's still good to learn other approaches and if I can remove a few actions from my macros by using your solution, that's always a plus.
Thanks for that!
That sounds like a good way to exercise the brain.
Today I was working on this macro again, trying to finish it, and I noticed that your solution (for this particular macro) won't work, because I actually need the path itself.
I will keep your solution on my notes anyway, in case I need the name (which I'm sure I will).
Now I need to go back to the simple form: find "$KMVAR_Local__FolderPath" -type d
but I would like to exclude 2 folders: /Users/dannywyatt/Library/Mobile Documents/iCloud~md~obsidian/Documents/Danny Wyatt/.obsidian
and /Users/dannywyatt/Library/Mobile Documents/iCloud~md~obsidian/Documents/Danny Wyatt/.trash
I was reading the topic below, but can't really understand how to achieve this
When I try this, it actually just shows me the .obsidian path, instead of excluding it: find "$KMVAR_Local__FolderPath" -path "/Users/dannywyatt/Library/Mobile Documents/iCloud~md~obsidian/Documents/Danny Wyatt/.obsidian" -prune
It seems macOS is different about the syntax. It took a bit of experimentation, but I think this would work:
find "$KMVAR_Local__FolderPath" -type d -name ".obsidian" \
-prune -or -type d -name ".trash" -prune -or -type d
Basically you have to use a -name flag before each thing to exclude, you have to list only the folder name within the top-level folder that you're searching (....Documents/DannyWyatt in this case), and (this is what was tripping me up), you have to add and -or -type d after each prune, or find will simply stop searching.
Please test and let me know if it works for you; it seems to work here in my testing. (You can remove the \ + line break from the above; I added that just to prevent one wide line in the post, though it should work as shown, too.)