Import only new files from directory tree

I use Zotero to manage scientific papers because it can download/rename PDFs automatically. The PDFs are stored in subfolders with random names. This setting cannot be changed unfortunately.

…/zotero/yslkdfhjsgf/file1.pdf
…/zotero/skjdflfgh/file2.pdf
…/zotero/34jh5lhj345/file3.pdf

I would like to import all PDF files from the subdirectories into one folder in Devonthink. Ideally, I would like to import only PDFs which are not in the database already (i.e. skip duplicates).

I have used Devonthink a lot but never scripted anything. Is it possible to create an import script for my use case?

While this should be scriptable, an easier approach might be to index the folder (see e.g. File > Index…)

Indexing would include the random subfolders and I prefer to import.

I do not really know how to get started with AppleScript, is there a tutorial with examples for Devonthink?

Indexing might be nonetheless an option together with smart rules (“Zotero” is the indexed group on the screenshot, “Target” is the desired destination for the imported documents):

Like @cgrunenberg suggested, indexing and smart rules would work.

However, I wanted to learn scripting DevonThink and wrote an AppleScript that imports the PDFs and deletes duplicates.

In case anyone wants to do the same: https://github.com/mpreusse/zotero_to_devonthink

Interesting approach.

PS: When posting a gist, you may want to consider saving a copy of the script as text, i.e., an .applescript file. This will show the code in the gist instead of requiring a user to download the script. They can examine it and copy / paste into a new script if desired.

Good point, done!