I often print articles that I come across on the 'tubes to PDF in a specific folder, which has the “Import” folder action attached. I noticed that some of these I had to go and import by hand, which irritated me.
Of course, the (rather simple) problem was that OS X created the PDF file (which triggered the import script) and so, for long documents, OS X would still be writing to the file while DEVONthink was trying to import it, and so it’d fail.
The solution was just to toss a delay in:
-- Action Import.applescript -- DevonThink Pro -- Created by Christian Grunenberg on Tue Dec 03 2002. -- Copyright (c) 2002-2005. All rights reserved. on adding folder items to this_folder after receiving added_items try tell application "DEVONthink Pro" to launch repeat with theItem in every item of added_items try set thePath to theItem as text if thePath does not end with ".download:" then delay 10 tell application "DEVONthink Pro" to import thePath end if end try end repeat end try end adding folder items to
The 10-second delay might seem long, but I just checked and the folder actions queue up very nicely (in Leopard at least), so it shouldn’t cause any untoward behavior.
DEVONthink Pro tests the file before actually importing it, I presume from the graceful error – would it be possible to build in a little timeout period of ten seconds so that if a file is being written when an import is requested, it’ll wait a bit to see if the action completes within a few seconds?