Multi-document Find and Replace

I’m sure this feature has been requested before, but a search of the forum didn’t turn up any posts. I think that this capability is essential in an otherwise superb “Professional” application.



It might be dangerous,but in fact I’ve never had trouble with other apps, such as BBEdit, in which multiple-file search and replace is well-designed. Why should it be any different in DTPO? One creates a set of the files to be searched and and sets options about whether to confirm each change. A robust “undo” capability certainly helps.

I came across this issue today when I wanted to change all the instances of a single term to a variant–neither was a misspelling. I knew exactly which documents contained the word to be changed, but having to search and replace document by document was truly tedious. I even thought of exporting the documents to text files so that I could use BBEdit.

Of course, a regular expressions facility would be a natural accompaniment to good search and replace functions. The new search commands taken from Devon Agent are a good start, but, in my opinion, the search and replace capabilities in DTPO could be greatly improved.

There is an easier way at least for plain text files - but not for the faint of the heart :wink:

you can point BBEdit to the folder in the database-package and perform your grep magic on all files in there:
DTP will pick up the changes without problems. Just make sure not to have any unsaved open windows in DTP.

I wish I could do that with rtf files as well and I would support the feature request for multiple document search and replace (grep support is always nice to have but for a starter a standard search and replace would be enough).


I too would love to see this feature added

I’d like to see this feature too

Came across Brett Trepstra’s discussion of “tops” - a command line utility that can be used to replace text in multiple files at once. Should be fairly easy to implement a DEVONthink script that calls “tops” for each file in a selection.

(“tops” might be part of the Developer Tools - open a Terminal session and do “man tops” - if there’s no manual displayed, you don’t have “tops” on your machine.)

Update: I’ve posted an experimental find-and-replace script using “tops” here.

[Cross-posting this here as well.]

From what I can tell, no changes have been made within the app to support multi-file search-and-replace, so I figured I’d share the solution I ended up using in case it helps someone else down the line.

While @korm’s script is much appreciated, the warnings gave me pause, so I sought something a little more robust and familiar. Enter VS Code.

:warning: I haven’t spent enough time with this to be 100% sure that I didn’t bork something. So far so good, though. :nerd_face:

Use Case

I have a few thousand markdown files exported from Ulysses representing about 5 years of world-building notes for a future fiction book series. About two years in, I changed the name of a major character, but didn’t bother to go back and fix it because, well, Ulysses also doesn’t have a global search-and-replace. :pensive:

I’d already imported all the files into DT by way of discovering whether it’s got what I need to help me rediscover my own thoughts (answer: probably!). I’d also completed a major tagging exercise designed to help me track the source of each note as I begin to slice and dice and rearrange them. Only mentioning this because, if I’d known that global search-and-replace wasn’t going to be available in-app, I’d probably have reversed the order, fixing updating the character’s name in the original markdown files before importing into DT.

The Solution

  1. Prep

    • File > Export > Database Archive… #safetyfirst!
    • Smart Group to collect all files containing the old character name
  2. Update document titles

    • Select all files in the Smart Group
    • Scripts menu > Rename > Replace Text…

    This allowed me to change ever occurrence of “Adrian” to “Adrim” in the file list.

  3. Update file contents

    • Right-click on the database and select Show in Finder
    • Right-click on the revealed .dtBase2 file > Open With > Other…
    • Select Visual Studio Code
    • Perform a global replacement in VS Code, being careful to use whole-word search and carefully inspecting the search results before performing the bulk replacement. Caveat lector: this is where it’s possible to do some real damage if you don’t know what you’re doing!

    Once VS Code had saved all the file changes, they appeared instantly in DEVONThink! #problemsolved

Needless to say, this should work with any other text editor, be it a command-line tool, Atom/Sublime, BBEdit…whatever. It’s rather wonderful that DT’s “database” is just a file bundle rather than in some inscrutable binary, thus enabling this kind of back-door power fix.

Thanks again, DT Team!