Automator Service to Import+OCR+Delete Files OR FolderAction

Hi,
Was looking arround in the forum but did not find any solution.
My scan workflows deliver the scanned pdf files into an inbox at the local HD. I initialy defined a Folder Action to automatically import these incomming files into DevonThink. Although using the supplied DevonThink Folder Action Scrits (DEVONthink - Import, OCR & Delete.scpt). I was not able to get stable persistent running of folder actions. The folder action runs for certain time but then stops for some unknown reason, until the folder action is deleted and redefined.
So I thought about using Automator’s Service approach. So far so good the Service was simple defined, with a small flaw:
I was not able to define the service the way that the imported and OCR’d files are deleted from the source location, instead of move it is a copy to Devonthink. I would like to have same functionality as the folder actionscript (DEVONthink - Import, OCR & Delete.scpt) does.

Can Anyone help?

regards

Found the solution:
Use “Set Variable” and “Get Variable”:

  1. Get the files
  2. Set a variable
  3. Call DevonThink’s OCR
  4. Get Variable
  5. Call Finder’s move to trash

sasha

I too have found that Folder Action doesn’t always work. I think (although I haven’t definitively demonstrated this) that it usually fails after I’ve manually changed the contents of the folder - i.e. deleted or copied its contents, or added a number of files all at once. If I leave the folder alone (i.e. allow Hazel to move files to it) or move files to it singly, my impression is that the Folder Action works flawlessly. I’m not familiar enough with Folder Actions to know whether this is a known “gotcha”.

Hi,

The folder actions are definetely not reliable. I will give it up and implement a scheduled task which runs every 30s doing the job.

regards

I think I have found the reason why my folder action scripts used to stop functioning without any reason:

The import and ocr took too long and the applescript threw an time-out error.

The original code is:

on adding folder items to this_folder after receiving added_items
	try
		if (count of added_items) is greater than 0 then
			tell application id "com.devon-technologies.thinkpro2" to launch
			repeat with theItem in added_items
				try
					delay 5
					set thePath to theItem as text
					if thePath does not end with ".download:" then
						tell application id "com.devon-technologies.thinkpro2"
							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

this portion shall be added


with timeout of (30 * 60) seconds
end timeout

resulting in

on adding folder items to this_folder after receiving added_items
	with timeout of (30 * 60) seconds
		try
			if (count of added_items) is greater than 0 then
				tell application id "com.devon-technologies.thinkpro2" to launch
				repeat with theItem in added_items
					try
						delay 5
						set thePath to theItem as text
						if thePath does not end with ".download:" then
							tell application id "com.devon-technologies.thinkpro2"
								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 timeout
end adding folder items to

The reason I beleave this might be the solution is, that I messed arround folder actions with no satisfying results, turning that into running 15s schedule with applescripts. Doing that I still hadd the same problem. Finally I found the reason in time-out errors thrown. Adding the “with timeout” statement my scheduled scripts run as expected.
One day I might go back to folderactions back.

So far, so good. That seems to work better. Thanks!