Multi-File Find/Replace

At this point I’m mainly curious if it’s possible using Scriptable to do a multi-file regex find/replace for an entire folder structure in iCloud.

My use case is this: I am using NotePlan, an amazing note taking/task manager tool which is 100% text based. One of it’s features is nested tags similar to Bear. Unfortunately they don’t have the tag rename built yet, so I would like to use scriptable to change my tags across all the textfiles in the noteplan folder. With Mac sandboxing, I wasn’t even sure if that was possible.


It should be possible.

I did a quick check and while the documentation indicates it only lists files, the list contents will list directories too. At least that’s my conclusion from this.

let objFM = FileManager.iCloud();
let astrContents = objFM.listContents("/");

The isDirectory function will let you determine what is a file and what is a sub-directory.

Using that you should be able to write a recursive function to traverse the file structure and pick out all the files.

With each file you would read the content, apply your regex update, and write it back.

However, you did note “Mac sandboxing” at the end. If you do have a Mac, there are many tools, that would allow you to find and replace across files. Those files if they are synced to iCloud and iCloud is enabled on your Mac would be accessible. I work with several sets of apps (including Scriptable) from my Mac in exactly this way.

Hope that helps.