Using Hazel for the Sorter

Hi,
I´m putting lots of stuff into the Sorter, emails, PDFs, Vides etc.
With the help of Hazel I can change the file name into a combination of the date of modification date + the file name. This works for other folders n my Mac BUT NOT for the Sorter folder.
So I could drag the files into any defined folder and move it from there not the sorter. But changing the files dragged into the sorter with the help of Hazel would be much more comfortable.

Is there any solution?

Frank

No, the Sorter folder does not function this way.

This is the easiest method.
Or you could define a Hazel rule that would direct the output to a particular Group in DEVONthink and bypass the Sorter altogether.

Hi,

Do you have link to some docs that would show how to design a rule in hazel that will send a file directly to a database/group in DevonThink?

Thanks!

The action would be to run a script - usually embedded. Here is a very simple approach to the code (noting it’s not the only solution, but should work as expected.)

set DB to "myDatabase" -- This is the name of the database to be used
set dest to "/Travel/Australia" -- This is the group to be used. Group locations MUST be entered in this fashion.

tell application id "DNtp"
	if DB is not in (name of databases) then -- You need to check if the database is open.
		display alert "Database " & DB & " is not open!" & return & return & "Please open it."
		return
	else
		set destinationGroup to get record at dest in database DB -- You need to specify the database, otherwise the current database will be queried. A VERY likely scenario since you'd be working while Hazel works in the background
		set newRecord to (import theFile to destinationGroup)
		if (exists newRecord) then tell application "Finder" to delete theFile
	end if
end tell

Hi,

This is great. I have a an import script running that’s pulling files in from hazel and putting them into the right groups. Something I noticed is that the imports are not marked as unread. I tried something like this:


	# Snip

	# theFile is provided by Hazel
	set theFileName to (the name of (info for theFile))

	# Snip

	# dtDestinationGroup is set earlier
	set theRecord to import theFile name theFileName to dtDestinationGroup
	set unread of theRecord to true

	# Snip

I do get a new record, and it’s in the right place, but he record is not marked as unread.

Am I missing something there?

Thanks,

Jeff

Ah, I got it. Works now.

I’ve included here what the overall script looks like for anyone interested.

It is triggered by Hazel which monitors a folder where another tool I have drops off downloaded receipts from, for example, Amazon and Paypal. The script looks at the file names and automatically imports the files to DevonThink and places them in the correct groups in a set of household folders I have set up. I went with UUIDs instead of DevonThink paths as I figure I might re-org folders and the UUIDs would stay the same no matter what.



# Basic settings

set dtDatabase to "Home"
set dtDatabasePath to "[POSIX path to Database]"

set alertEnabled to false
set testEnabled to false

# Import Group Definitions

# Inbox in Home Database
set dtGroupInboxHome to "[UUID of Home Database Inbox]"

# Amazon
set prefixAmazon to "Amazon"
set dtGroupAmazonUUID to "[UUID of Amazon Group]"

# PayPal
set prefixPayPal to "PayPal"
set dtGroupPayPalUUID to "[UUID of PayPal Group]"

# Insert other files to detect here...

if testEnabled then
	# If testing, supply a POSIX path to a valid PDF here.
	set theFile to "[Path to test file]"
	
	# If testing, supply the UUID for a valid group here.
	set dtGroupTestUUID to "[UUID of test group]"
	
end if

tell application "DEVONthink Pro"
	
	activate
	
	if dtDatabase is not in (name of databases) then
		open database dtDatabasePath
	end if
	
	if alertEnabled then display alert "POSIX path: " & (the name of (info for theFile))
	
	# theFile is provided by Hazel as a full path, get just the name part -- we don't want to preserve folder structure.
	set theFileName to (the name of (info for theFile))
	
	if theFileName begins with prefixAmazon then
		
		set dtDestinationGroup to get record with uuid dtGroupAmazonUUID in database dtDatabase
		if alertEnabled then display alert prefixAmazon & ": " & theFileName
		
	else if theFileName begins with prefixPayPal then
		
		set dtDestinationGroup to get record with uuid dtGroupPayPalUUID in database dtDatabase
		if alertEnabled then display alert prefixPayPal & ": " & theFileName
		
		
		# Insert other conditions here.
		
		
	else
		
		set dtDestinationGroup to get record with uuid dtGroupInboxHome in database dtDatabase
		display alert "Unknown file: " & theFileName
		
	end if
	
	if testEnabled then
		# Override to test group destination
		set dtDestinationGroup to get record with uuid dtGroupTestUUID in database dtDatabase
	end if
	
	set theRecord to import theFile name theFileName to dtDestinationGroup
	set unread of theRecord to true
	
end tell