Auto-tag scanned files?

Hi –

I’d like a way to automatically keep track of my scanned files (as opposed to files that I import manually). I use a ScanSnap. What would be great is is there was a way to get DTPO to automatically add a tag such as ‘Scanned’ to anything in the inbox from the ScanSnap. I can’t seem to find a way to do this. Ideas?

Rather than scan to the inbox, create a special folder and attach the following Folder Action script to that folder. Scan to that folder, and DEVONthink will import that document into the incoming group and add the tag specified in the “myTag” property in this script. (Default is “Scanned”)

“Incoming group” is determined by DEVONthink > Preferences > Import > Destination

Copy the script from this posting. Open AppleScript Editor. Paste the contents and then save as a compiled script to ~/Library/Scripts/Folder Action Script. To attached a Folder Action script, create the folder, then select it in Finder and choose Services > Folder Actions Setup…. Follow the prompts.

-- DEVONthink - Import Add Tag & Delete.applescript
-- Based on Import & Delete script Created by Christian Grunenberg on Fri Mar 26 2010.
-- Copyright (c) 2010-2012. All rights reserved.
-- Adjusted 20130613 by korm to add a tag to the record

property myTag : "Scanned"

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
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "com.devon-technologies.thinkpro2"
							set theRecord to import thePath to incoming group
							set the tags of theRecord to myTag
							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

Ahh, perfect! I was thinking that maybe there was an Applescript way to do this, but hadn’t gone down that path. Thanks a bunch!

I’m trying this and I’m getting an Applescript error on the line

set theRecord to import thePath to incoming group

It’s choking on ‘thePath’: Syntax Error: Expected end of line but found identifier

Does it work for you?

Yes, it works over here. (I test these things before posting them.)

The script is merely the same script as the folder action script DEVONthink - Import & Delete that is included in DEVONthink’s download. (To install DEVONthink’s folder action scripts choose DEVONthink > Install Add-Ons… > Folder Action Scripts) The only additions I made were these lines:


property myTag : "Scanned"
....
set the tags of theRecord to myTag

You might install those scripts, and open the one mentioned in AppleScript editor and attempt to compile it. If you get the error with the script that shipped with DEVONthink, then you have other problems on your system, and not the script.

The most common cases for that particular compiler error are either misspelling or incorrect line endings. (I can force the error over here, for example, by changing incoming group to incoming grou and attempting to compile the script. Because the DEVONthink dictionary property is “group” not “grou” there is a compiler error.)

Possible sources of the error include

  1. The script was not copied correctly, or there is a missing line ending or other copy/paste issue.
  2. The script is not being executed as a folder action – see the instructions in my original post. This is not a script menu script – it is a folder action. Normally, folder actions do not throw off error messages; they fail silently. If the error is at compile-time, then see the comment above.
  3. You are not running DEVONthink Pro Office 2

Hah – I guess I was trying to outsmart it by messing with things. Followed your directions exactly and it works great. Thanks!

In case it’s useful to others, I also had to change ScanSnap Manager -> Settings -> Application -> ‘None (Scan to File)’. Then in Settings -> File Option, I had to re-enable ‘Convert to Searchable PDF’, since that apparently was disabled by default on the ‘None’ profile.