So, basically you want a tree-like listing of all your files/folders with all the metadata. I’m not convinced that this easily done with MD/text or CSV. Suppose you have a structure like this
Folder1
|---------File 1
|---------File 2
|---------Folder 2
|-----------File 1
|-----------File 2
then File 1 and File 2 would appear in two different folders – same name, different entities. Therefore, JSON might be the better choice. A basic (very basic) script might look like this:
(() => {
const app = Application("DEVONthink 3")
app.includeStandardAdditions = true;
const initialGroup = app.getRecordWithUuid('28258F1A-FC1D-49C6-97B4-F5C8DA21265B');
const metadata = [];
getMetaData(initialGroup, metadata);
console.log(JSON.stringify(metadata));
})()
function getMetaData(record, metadata) {
// console.log(group.name());
if (record.type() === 'group') {
const groupInfo = {name: record.name(), type: "folder", metadata: record.customMetaData(), content: []};
metadata.push(groupInfo);
record.children().forEach(r => {
getMetaData(r,groupInfo.content)
})
} else {
const fileInfo = {name: record.name(), type: "file", metadata: record.customMetaData()};
metadata.push(fileInfo);
}
}
In this incantation, the script works on a particular group defined in the call to getRecordWithUuid
. It outputs a hierarchical structure of folders and files representing all the groups and records included in the initial group, including all the custom metadata. You can, of course, add tags and other metadata like title, creation date, whatever. That would have to happen in the lines setting up groupInfo
and fileInfo
;
As to the path
missing from the metadata overview: given that your data can reside anywhere in your file system, and you’re planning to move it around after saving the metadata, I doubt that this information is particularly useful.
As to “formatted text” in metadata: According to the documentation, that’s “Rich text”. You could use the command line utility textutil
to convert it. But after I saw what a rich text field gives in JXA and AppleScript, I’d give up all hope on that one. Perhaps @cgrunenberg can shed some light on that issue? What I see here (in script editor) is this:
tell application "DEVONthink 3"
get record with uuid "A95457F9-C064-4793-9906-16CA534DA2A7"
get custom meta data for "mdrt" from content id 84902 of database id 2
Ergebnis:
error "«data ****72746664000000000300000002000000070000005458542E727466010000002EBC0100002B00000001000000B40100007B5C727466315C616E73695C616E7369637067313235325C636F636F61727466323730380A5C6
…000000000000000» to text
(That’s for AppleScript, in JXA the result is similarly unusable).