To my understanding, replicated files and folders are exported by DEVONthink as duplicates. Is there a script or technique for exporting only one actual instance of the exported item in Finder, and using macOS aliases or symlinks for any other instances?
I believe there might be a misunderstand of what a replicant is. A replicant is merely an entry in DEVONthink’s metadata for the current database that makes it appear that multiple instances of a document exist in multiple places, but underlying this is only one physical document. If you drag a replicant to the file system (in Finder or other app), behind the scenes DEVONthink moves a copy of the original file to the file system.
The concept “one actual instance” has no meaning. Exporting is exporting: copy this from here and put it there.
Our understanding is actually common. Indeed, in the DEVONthink model replicants are effectively pointers to an item (“content”) that actually resides in the database, whereas in the Finder the “content” file and any symlinks/aliases to it are all located within the filesystem.
What I am trying to achieve is produce an export which will functionally mirror the DEVONthink model as closely as possible. One solution would be to export each “content” file only once, and reproduce the entire DEVONthink file/folder structure using symlinks/aliases to the respective content files as substitutes for replicants.
For the first part of your question: All replicants share the same item link. So a script that exports a number of items one by one could save the item links of all of these exported items in an array. And before it exports an item it could look up if its item link is already in the array and if so: not export the item.
That would allow to avoid having more than one copy of an item.
But that leaves out the second part as it would not mirror the structure of your data in DEVONthink, including what have been replicants.
It’s beyond my scope if it it feasible to add the item link to the exported item, say, as a tag and have a script check if the item link of an item that should be exported is amongst the item link tags of the files in the external location and if so create an alias to one of these files instead of a copy of the file. (Which would be an original plus aliases model and as such opposed to what replicants in DT are, true. But it would keep the structure.)
And I am even less sure if that would work from inside of DEVONthink.
What do you intend to do with smart groups – create saved searches in Finder?
And symlinks are probably not what you’re after. Hardlinks should mirror DT’s replica more closely, as they point to the same inode.
@suavito: Every item in DT has a property that tells you if it’s replicated. So, if you stumble upon an item that is already exported and replicated, you just create a hardlink to the first exported item.
Hm. What is the point in mimicking DTs approach if you do not have DT? You’ll lose all the metadata (tags, custom metadata, flags, whatever) on Linux, anyway. Why invest energy in keeping the structure?
Migrating to Linux is not an “asteroid hits the earth” kind of scenario. I may have to, for reasons unrelated to DEVONthink.
Not static, but this is not a problem. It is easy to craft keyboard shortcuts for producing aliases in the filesystem, and for moving things around between directories. (Wiki-style links would break, but this is beyond the scope of my question.)
Because I am used to the structure—it has been growing organically for almost two decades—and it represents the mental organization of my knowledge, intuition, and ideas. This is especially the case with my main database, which is huge and not project-specific.
Because I want to maintain the folder structure and maintain the identity between “replicants” (if I edit one, the change should be reflected everywhere).
So, you export to mac with its APFS and plan/envisage to migrate that to Linux with a completely different filesystem?
How will links etc be preserved in that process?
An alternative way, of course, would be to produce a regular export from DEVONthink (with replicants exported as duplicate files), then run a de-duplication script in the terminal to replace all but one instances of each file with symlinks or hard links.
If you really want to do that, there are apps such as Tidy Up, from Hyperbolic, that let you make a finder duplicate into an alias - the issue here is that you have to tediously tell Tidy Up which is every folder that is supposed to contain the “original”. If your structure is not too complicated, it’s doable. If it is, well.
I did this years ago with a vast collection of legacy files and folders that were not related to DEVONthink, but where I for a number of reasons had created many aliases.
The problem of determining the “original” can be circumnavigated by having all “originals” heaped up within a hierarchically flat “archive” folder, and using hard links in the DEVONthink-like directory tree. A file watcher can be used to ensure that deleting a link will automatically deleted the eponymous “original” in the archive.
I now have the outlines of a solution—thank you for a useful discussion.
(@BLUEFROG there is no reason for defensiveness: My question is not intended to diminish the value of this great product, but only to solve a specific technical issue that I am facing. Thankfully the community, if not official support, gave my question a genuine thought.)