Is there a script for having DT auto-import files added to the Finder folder?

I’m trying to create the best of both worlds—indexing and importing—by having DT do a periodic sweep of folders in Finder where docs have been IMPORTED from. And just adding anything to my DT DB that is new. I am aware that indexing will do that, but that also risks the loss of an indexed file if it is moved or removed from the folder in Finder.

The use case is that my organization shares document repositories accessible in Finder, and documents are constantly being added, but I’m the only one that uses DT to actually work with the documents. If I simply index, but someone moves something on me, I risk losing the annotating and other work I’ve done inside DT. Without some form of monitoring of the Finder folders I have to do a periodic MANUAL import. Which also runs a risk of creating tons of duplicates.

The other workaround I’ve tried is cloning the Finder folders to my HDD, indexing from that source and keeping a one-way sync set up where things added to the group Finder are added to my HDD cloned folders. But because it’s a one way sync, deletions of docs in group Finder aren’t tracked. But that solution is cumbersome, requires setting up and maintaining lots of different sync tasks and winds up gobbling HDD space with cloned folders.

How about:

(1) Indexing a folder and setting up a Smart Rule to automatically Import to Database all new items; or

(2) Set up a Hazel rule to copy/duplicate new files from your designated Finder Folder(s) to some other folder which in turn is Indexed to DT3

Thank you. I will explore those ideas.

1 Like

So I have successfully added a Hazel rule that monitors the source file, and adds new docs to the clone file. But I don’t see how to create a Smart Rule in DT that IMPORTS new documents into the appropriate DT database. I am aware that indexing will keep the DB current, but if I prefer to import, can that be done? The available syntax for Smart Rules does not seem to include the ability to monitor a folder (with nested subfolders) outside of DT. I might be wrong.

There is no need for other software if you use folder actions script in macOS. I just happened to test them in Big Sur and they still work.

  • Open Finder
  • Choose a folder
  • Right click that folder (context menu)
  • Select Folder actions at the bottom
  • Choose one of the available scripts supplied by DT
  • Enable the folder actions by clicking the checkbox

From now on, every time you add a file, it will be imported into DT. Some scripts also delete the file (what you don’t want if I understand you correctly), so you might need to copy and adapt it in the script editor or select a script that doesn’t delete. And it might be you need to install add-ons from DT first, but it could be the folder action scripts are installed by default (I’m not sure).

See page 200 of the manual:

2 Likes

Indeed as that’s a core requirement of a smart rule, targeting a location.

Set up a watched folder in the Finder and index it, ideally in the Global Inbox or the Inbox of a database. Then use a Move Into Database action to import the file into the database.

It would be best to use a temporal criterion, e.g., Date Added is This Hour or to use a Move action at the end to remove it form the watched group. This avoids potentially reprocessing the file.

2 Likes

The question is wether the files are just added once to the watched folder or if they get modified. And if so should the modified files get moved into DEVONthink too?

Instead of a temporal criterion you could use tag is not: imported as a condition and add the tag imported (or whatever you like to call it) to the original Finder file at the end of the importing rule.

Yes the poster would have to provide more information for more specific advice.

While I couldn’t find any way to get Folder Actions to work on Big Sur, I did discover on the Hazel forums that any file in the folder “~/Library/Application Support/DEVONthink 3/Inbox” automatically gets imported to DT. So I created a very simple Hazel rule to watch a Dropbox folder and move any new files to that folder. This seems to work… as long as you don’t need that file in a particular group.

Did you try what I suggested above?
There should be no need to use an outside utility (or Folder Actions) for the simple process outlined in this thread.

“Set up a watched folder in the Finder and index it, ideally in the Global Inbox or the Inbox of a database. Then use a Move Into Database action to import the file into the database.”

Can you explain how to do these various steps? None of this made any sense to me.

  1. You already have a folder in the Finder Hazel is watching. Stop Hazel from watching it.
  2. Go into the Global Inbox or the desired database in DEVONthink.
  3. Select FIle > Index Files and Folders, navigate to the folder in the Finder, and press Open. This folder has now been indexed, i.e., it remains outside the internals of the database but DEVONthink is aware of it.
  4. Create a smart rule per my example above making sure to target the indexed group in the database. When a file is added to the folder in the Finder, the chain of actions should run as specified in the smart rule.
1 Like

Thanks, but can smart rules run automatically? So far, I can only make them run by control clicking on them and selecting “apply rule.”

My rule shows it’s using the On Import event trigger which runs after a file is detected in the indexed location in this case.

One possible exception is if you have the indexed folder in a cloud-synced location, e.g., Dropbox. Changes in such a folder may not initiate a filesystem event. However, there are other event triggers, like Before synchronization that can be used.

This is all discussed in the Help > Documentation > Automation > Smart Rules as well as Appendix > Smart Rule Events and Actions.

1 Like

Thanks. I’ll look into this. Right now the Hazel rule seems to work perfectly, so I might wait till later to try to figure out the internal way of handling this. This is what the Hazel rule looks like:

The Hazel rule is simple and so would be the Smart Rule in DEVONthink. It would look a bit different but once you understand the the structure it won’t be difficult to create it (and many more useful Smart Rules). And @bluefrog described all the steps.

The difference between a Hazel and a DEVONthink rule is what they can achieve: The Inbox folder is the only one Hazel can move a file to to get it into DEVONthink. While a DEVONthink Smart Rule can move a file to any database or group you want it to be without any further step necessary.

Thanks for the further explanation. My hesitancy is because this is a Dropbox folder and it sounded like this might make things more complicated. Also, I did try to create some smart rules but they don’t seem to work reliably, even with triggers. It seems like I will have to sit down and read the documentation carefully to understand how it all works…

I’m indexing an iCloud Drive folder 1Writer on my iPhone and iPad saves its notes to. My Smart Rule does what yours is supposed to do when I get your right: I just moves the files into the database and to the destination* I want them to be.

Working with a cloud folder on this basic level never caused any problem for me. And I don’t see why it should, as long as there is an internet connection. It’s just a simple one-way action: Is something in the folder, drag it in.

Smart Rule event triggers can be a bit capricious according to my experience. But again in this case that is no problem: You could, like me, use an interval trigger like Every Minute additionally to, say, On Startup.

It’s really worth learning how Smart Rules in DEVONthink work. You should try them with dummy files first of course. And there will always be someone in these forum who helps when you got stuck.


* Actually “destinations”, plural. I have a default destination and when a file contains a certain tag a rule moves it somewhere else and removes the tag afterwards.

1 Like

I have been using smart rules effectively, but for some reason I need to trigger them manually :cry: When I have time I’ll try to look into what I’m doing wrong…

A Smart Rule has four major elements:

  1. Search scope (Search in …)
  2. Condition (for example: Kind is Any Document)
  3. Trigger (On Startup, On Import, Every Minute etc.)
  4. The action (for example: Move)

Every one of these four can cause a rule not to work.

And here is the good news: When you say you have to trigger your rules manually that means they can get triggered. I. e. part 4, the action, is working as intended! (So no tears here necessary.)

The next step: Select the Smart Rule in the sidebar and see if all the items are displayed in the item list that the Smart Rule should automatically process. (And when you have activated Display numbers of items inside groups activated in DEVONthink’s preferences—General/Appearance—the item count will indicate too if there are items the Smart Rule should apply to.)

If there are items that means that both part 1, the search scope, and part 2, the condition, are the right ones.

Which would only leave … the trigger.

3 Likes