Need help with a Folder Actions Script

In the past, I used Christian Grunenberg’s Import, OCR & Delete script to move files placed in a folder called “To Devonthink” into Devonthink, OCR them and then delete them from the original folder. Unfortunately, at some point that script stopped working, so now files placed in that folder just sit there; they aren’t imported into DTP, they aren’t OCR’ed, and they aren’t deleted.

I’m using DevonThink Pro 2.8.8 on a MacBook Air mid-2011 running OS X 10.11.2 El Capitan. I checked and the script is “attached” to the “To Devonthink” folder and Folder Actions are active and the script is selected. I’m not quite sure when the script/Folder Action/whatever stopped working, but I’m sure it’s been several OS X system updates ago (and perhaps several DTP updates ago as well).

The script I have is set forth below. Can anyone suggest a fix?

-- DEVONthink - Import, OCR & Delete.applescript
-- Created by Christian Grunenberg on Fri Jun 18 2010.
-- Copyright (c) 2010-2014. All rights reserved.

on adding folder items to this_folder after receiving added_items
		if (count of added_items) is greater than 0 then
			tell application id "DNtp" to launch
			repeat with theItem in added_items
				set lastFileSize to 0
				set currentFileSize to 1
				repeat while lastFileSize ≠ currentFileSize
					delay 0.5
					set lastFileSize to currentFileSize
					set currentFileSize to size of (info for theItem)
				end repeat
					set thePath to theItem as text
					if thePath does not end with ".download:" then
						tell application id "DNtp"
							set theRecord to ocr file thePath to incoming group
							if exists theRecord then tell application "Finder" to delete theItem
						end tell
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

(Fixed: BLUEFROG 2016-01-25)

First, I apologize for the formatting of the script in my last post. I’ve never posted a script here before, and don’t know how to post one with the indenting, etc., left intact.

Also, after poking around in other scripts posted here, I made two changes to the script I posted. In each case where the script originally used “DNtp” as the application ID, I changed that to “com.devon-technologies.thinkpro2”. After making those changes, the Import and OCR portions the script seem to work properly. However, the Delete portion of the script – i.e., the part that tells Finder to go back and delete the items from the “To Devonthink” folder – still does not seem to be working. In fact, I’m getting an error message, as follows:

The operation can’t be completed because one or more required items can’t be found.
(Error code -43)

However, the files to be deleted are still sitting there in the “To Devonthink” folder (the folder to which the Action Folder script is attached).

Any suggestions? I’m getting closer!!


And as one added note, if I try to manually delete any of the items from the “To Devonthink” folder (after the script added them to DevonThink and OCR’ed them), I’m getting the same error message as quoted in my previous message, i.e.,

The operation can’t be completed because one or more required items can’t be found.
(Error code -43)

I checked, and the files are there. I can open them and view them by double-clicking them, they are non-zero in size, and they still have their original creation dates.

Use of application id “DNtp" is the preferred method.

Note that Folder Actions can be fiddly and I wouldn’t expect them to work across OS updates. (Say a Hallelujah if they do!)

I would:

  • Remove the files that have been imported
  • Install the Folder Actions again
  • Remove the Folder Action from the folder in Folder Actions Setup, closing the FAS.
  • Reopen it and reattach the Action