How to specify target database and group when using "DEVONthink - Import, OCR & Delete" folder action script?

I’m an absolute AppleScript beginner and would like to modify the folder action script "“DEVONthink - Import, OCR & Delete” to upload to a pre-specified specific database and group. What is the best way to do this?

Currently use Hazel to monitor my Downloads folder and then move files to the relavant “import” folder - e.g. Receipts, PDFs to Read, etc. For each import folder I will attach a folder action to import, ocr, and then delete the contained files.


Rudy, I have zero knowledge of AppleScript so what do I do, …

If you use the Action Folder to get a file into the DT Inbox, why can’t you use Smart Rules to move files to where you want them in DT? In passing some users have reported a strategy of using tags (perhaps automatically added by Hazel) that can be used if needed as a trigger for a Smart Rule. Another approach is a bit different, you could use a indexed folder as a transition point [I call this no mans land :slight_smile: ] and this could be useful, for example to get DT to OCR files using Smart Rule if necessary but also allows Hazel to work on these files as well if relevant.

To get more useful feedback you really need to use a step by step example so readers can get a better idea of what is actually required

Thanks for the ideas @timaru.

This might be based on incorrect assumptions, but I prefer Folder Actions as I believe they run without Devonthink having to be open, whereas Smart Rules don’t. Do let me know if I’m wrong!

Here is an example workflow:

  1. Download receipts from internet to Downloads folder.
  2. (With Hazel:) Items identified as receipts based on source URL, file name etc. Tagged with “Receipt” and then moved to “Receipt Inbox”
  3. Folder Action triggered, which imports receipt to DT3 (ideally to specific Receipt database), indexes it, and then deleted it from the Receipt Inbox.

I doubt that folder actions can import anything into DT groups unless DT is running. Afaik, a folder action is basically a script processing files. So, in your case, it would require a tell Application("DNtp") somewhere, which would start DT anyway. But I may be wrong, of course.

On the other hand: since you want to work with DT anyway, for which it has to be running, what’s the problem with a smart rule doing what you want?

Also, folder actions are quite old technology and not really encouraged anymore by DEVONtechnologies, if I remember correctly.

1 Like

I am hardly an authority but if I put something in a Folder with DT Folder actions and DT is not operating the files just get stuck in the folder & do not move into DT even when it is subsequently activated - you can test this for yourself. So I think your assumption is unlikely to be correct and I haven’t read anything along those lines in the documentation.

As an aside the advantage of using an Indexed folder as a clearing house is a file will be synced when DT is activated & then can be acted on by Smart Rules or Hazel.

Nonetheless from what you say you might have good chance of getting your files(s) into the global inbox and then using a Smart Rule to move the file(s) to the desired group in any database, (without even using Hazel at any point, other than to move to Action Folder/Inbox. Its is quite confusing at first - it took me a while to sort out Smart Rules and I do not do anything that complex.

Hope this moves you forward.

1 Like

I just tested it.

If I put a file in the selected action folder and DT is not running the folder activates DT. Nonetheless I do not see what advantage Folder Actions offer when Smart Rules are a better tool for certainly for people like me who don’t have time to learn AppleScript etc, …


You could still use Hazel to identify and move receipts into a folder. However, indexing that folder and using a smart rule to move files into the database - and any other subsequent actions you may want to do - would be the advocated method.

Not sure I’m following your entire workflow, but here’s an example of how I use Hazel to get a file to a specfic DT group. You can either name the group explicitly (but then can’t change it unless you change the script also) or by UUID. It should be pretty easy to run a smart rule to do the OCR once the file is in DT:

-- Import the file.
tell application id "DNtp"
	--set img_ib to get record at "/Investments/Schwab IRA" in database "FileCabinet"
	set img_ib to get record with uuid "B95617E8-FCBE-xxxx-8200-xxxxxxxxxxx"
	import theFile to img_ib
end tell