Customised folder action script that imports scans from user-specific cache folder into database-specific inbox

Dear all,

My setup is as follows:
-ScanSnap ix1600
-Synology NAS with 2 user-specific folders for caching the scans
-DevonThink 3 with 2 user-specific databases

Since the last ScanSnap update, it can now save the scans directly in folders on the NAS (without the diversions via cloud services such as GoogleDrive). For the automatic import of scans that end up in such folders to DevonThink, there is the folder action Apple script “Import, OCR & Delete” (right-click etc. to attach to the corresponding folder), which I would like to use. However, all scans imported in this way end up in the same global inbox.
I would now like them to end up directly in the database-specific inbox of the respective user instead. So all scans from NAS folder A end up in Inbox A, all scans from NAS folder B end up in Inbox B. This probably requires the specific storage location to be integrated into the script, i.e. the script must be adapted accordingly. However, I have not yet succeeded in doing this.
I would appreciate any tips on what exactly I need to change in the script. The script looks like this by default:

The customized script looks like this:

Can someone tell me how to change it to make it work?

Best regards & thanks!

What does that mean? And perhaps indexing the NAS folders in DT would simplify things.

Please post code as such, not as screenshot. Typing in what one sees in an image is tedious and error-prone.


My customised script is not working and needs to be modified to make it work.

If the script would work, I think this workflow is pretty simple. Maybe there is an easier way, maybe you can elaborate and provide context on what you mean by indexing and how it would look exactly.

I tried to post the code (copy-paste) but it looked messy, maybe because it was in preview mode.

But you have it there already: Replace with /name of database/inbox.

You can index folder instead of importing them into the database. You can find the feature under File - index folders

Hi SteffisCloud

The “critical” line of the script currently looks like this but it does not work:

set theRecord to ocr file thePath to create location “/mydatabasename/Inbox”

It contains most likely a minor syntax error related to the naming of my inbox. The default DEVONThink script works perfectly.

Kind regards

While that might be true, it doesn’t tell anybody anything. Not working can mean:

  • it doesn’t do anything
  • it does something you don’t want
  • it does something you want but not everything.

Therefore, a detailed description is needed so that others understand what you are seeing or not seeing or wanting to see.

Code can be posted as text by including it in three backquotes like so:
code goes here

And try running your code in Script Editor. There, you can follow easily which steps are executed and what the result of each step is.

Then there’s the manual that explains the difference between indexing and importing. And a bunch of posts here discussing that. I still think indexing the relevant NAS folders into DT and using smart rule(s) that move(s) new files into the desired database location is a simpler solution – folder actions are a bit out of fashion.

Searching in the forum for “Scan import” or so might give you some pointers.

1 Like

Hello Chrillek

May I ask: Do you see an error in the line of code in question and if so, what is wrong?

By “not working” I meant that DEVONThink does nothing when running the code in question, while the default code works perfectly. There is no error message in DEVONThink or Script Editor. Since it is likely that only one line of code is affected, hopefully the problem is not too difficult.

I am explicitly looking for a solution with the “Folder Action” mechanism. The mechanism with Indexing & Smart Rule is known to me, I implemented it 2 years ago and it basically works, but unfortunately the reliability is not 100% and the solution does not seem to be the best in terms of elegance, because it only checks every minute if a new file has been scanned, and not directly on receipt. I’ll see which of the two solutions works better in practice.


Why, when alternatives have been suggested?

Also, I would recommend you read this blog post:

If script editor doesn’t see an error, how would I? Also, I suggested to look at the trace of your script in script editor. Did you do that? What did it tell you about the line in question?

And why do you try to create a location in the database that’s there by default instead of using incoming group, perhaps like so:
set targetGroup to incoming group of databases["yourDatabase"]
(I don’t speak AppleScript, so that’s only a vague approximation)
Also, why bother with (re-) defining the target group for OCR in each iteration instead of setting it as a constant for once before the initial repeat?

Hello Bluefrog

Thank you for your involvement. I had set up such a combined indexing/smart rule in 2021, which went a little further than described in the linked article (see my post from back then Save ScanSnap scans to the Cloud/NAS and import them with DevonThink). It worked, but not 100% reliably. I now wanted to try Folder Actions, as I understood this to be the propagated standard way of importing. However, as this does not seem to be the case, I am sticking with my indexing/smart rule solution. Hopefully the problems from back then, which were possibly related to the import diversions via Google Drive, will disappear.

Best regards

You’re welcome!

Folder Actions aren’t deprecated and there can be times when they’re still useful. However, smart rules are recommended nowadays for these kinds of actions.

Hello Chrillek

Thank you very much for your analysis. I ran the scripts in the script editor, but did not find any log history (see picture). So much for that.

I must say that I have no in-depth expertise in Apple Script & DevonThink myself and have this code from a third party. In this respect, it is very possible that your points of criticism are very valid, namely that the chosen procedure with the defined location in the database is not ideal. I tried your suggested code, but it didn’t work right away, which may be due to one detail.

My reasoning behind the request was that I am hardly the only one with such a setup, namely that several users are used and a correspondingly adapted folder action script would be needed. It looks like the Index/SmartScript method is increasingly the preferred method for import jobs, and I’m going to use it productively for the time being and hope that the quality issues of the past are a thing of the past. Still, I’d be interested to know how it would work with the folder action script, just out of curiosity.