Please forgive the uselessness of this question. I’ve been using DT for some time now but never tried to get on top of the scripting abilities, and now with custom metadata they have suddenly become potentially very attractive. I suspect there is something out there that is 70-80% of what I need but some basic searching has failed to turn it up so I thought I’d ask.
Suppose I have a CSV list of files, which includes the filename, and various metadata items for each file. I assume that if I knuckle down and learn how all this works I could write an AppleScript to iterate through the list and import the files with the metadata appropriately. But does anyone know of something out there already along those lines that I could tweak, rather than working it out from scratch? (Coding is not my day job, and not even the hobby it used to be …)
OK I didn’t read that closely enough the first time
Are these files located randomly, or are they together in a folder somewhere?
WIll this be an ongoing process or just once to set up a database?
If they are located in the same folder or in a small number of folders, you can fairly easily Index those folders and then if desired choose to import the indexed files into the database.
Many thanks for the replies. The files would be in a folder. The catch is that I want to import them and set metadata for each imported flile per other items in the same CSV entry. So for example it might look like this (not replicating CSV coding):
File path | Document name | Custom metadata 1 | Custom metadata 2 | Custom metadata 3
docs/doc1.pdf | “Memo from Fred” | Apple | Guns | 3 January 2016
docs/doc2.pdf | “Directions to mountain” | Banana | Rope | 2 August 1958
The filename and the Document Name are not the same here. You can’t set the title of a PDF as it’s read only. However, if the PDF has the title in place, it will be part of the import.
You need to define what the custom metadata names are.
set docsPath to "~/Desktop/"
-- I am using this variable as your example text showed an incomplete path.
-- Using the variable above would import from files on my desktop.
-- Using a full path in the CSV could supersede this method.
tell application id "DNtp"
set doc to (item 1 of (selection as list)) -- Handling a csv file selected in DEVONthink
-- Get the header names and set variables for the meta data names
set docHeaders to (columns of doc)
set md1 to (item 2 of docHeaders) as string
set md2 to (item 3 of docHeaders) as string
set docContents to (cells of doc) -- Get the contents of the cells in the file
repeat with csvItem in docContents
set newRecord to import (docsPath & (item 1 of csvItem)) to current group -- Import the file
-- Add the custom metadata
add custom meta data (item 2 of csvItem) for md1 to newRecord
add custom meta data (item 3 of csvItem) for md2 to newRecord
end repeat
end tell