DEVONthink, Hazel and Automator

Maybe I missed an announcement somewhere. But since I had posted the above and received Christian’s reply in April 2014, I hadn’t seen any real hints of the further development I had suggested - until a week or two ago (credit ScreenCastsOnline) I was directed towards Automator. Together with Hazel and DT’s Automator actions, an (unindexed) document outside a DT database can indeed be renamed and filed in the appropriate group within a DT database (note imported, not indexed) without user intervention - and all this without the need to write AppleScripts (for those of us who lack the skill). For me this is a terrific improvement, which will save me a lot of time and for which I am very grateful.

(As a postscript - I know that in the wider Apple universe there’s some discussion of whether automation features such as Automator will survive in the future. But whilst they do, wouldn’t it be worthwhile for DT to make more of this (I believe) very valuable functionality, and to provide instructions for ignorant users like me to help us use it?)

You didn’t miss anything, it’s still in the pipeline due to the delays caused by the new synchronization (introduced by version 2.9) and the completely rewritten DEVONthink To Go 2.

This and many more actions will be possible in the future without Hazel, Automator or AppleScript.

1 Like

Thanks, Christian. Good to know.

I have been using a Hazel folder action that includes an automator workflow for quite a while that allows me to conditionally tag and file items into a DTP inbox. The workflow is quite simple. It sets the current group to the inbox (v2.7.2) and then adds the item to current group by import (v2.0). Version numbers reflect version of the automator steps.

Recently, I have been seeing variable success with this action. Sometimes it files the document in the correct inbox and other times it ends up importing the file into a hidden folder with a ./pdf/… URL. I can only locate the added item by looking at imports from the current day. It doesn’t show up in any global or other inbox or any other folder within DTP, but it is in DTP.

Are there newer versions of these automator actions? Any ideas why this well established workflow isn’t running consistently?

I am on High Sierra 10.13.1 and DTP 2.9.16

Thanks,

Norm

I’m curious why are you running Automator actions instead of just using a simple embedded script?

I suspect many of us are somewhat intimidated by Apple Script & see Automator & Hazel as being more accessible. Is there a scripts library available which users could use?

Bill

@BLUEFROG, just wanted to see whether you have a simple embedded script (or recommendation) that would be better than running Automator actions as @BillW described is part of his workflow.

Thank you in advance.

There is more than one approach to handling the destination group, but this is a simple example…

set DB to "Test2" -- This is the name of the database to be used
set dest to "/Test2 Inbox/New Group 4" -- This is the group to be used. Paths for 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

Thank you kindly!

No problem. :smiley:

Thank you Jim for the script! This has helped me immensely to automate the import to specific folders into DT.

But now I wish to expand this a bit by adding tagging and OCR functions to the script. I just do not know how. Could you or anyone else help direct me in learning how to expand upon this script’s functionality?

Thanks!

You’e welcome.

Tagging within DEVONthink? Do you have Pro Office for OCR?

There is a Folder Action script - Import, OCR & Delete (installed in ~/Library/Scripts/Folder Action Script) that has a line on using OCR.

Tagging can be done with a list, like…


set tags of thisRecord to {"jim"}

```Yes, adding a Tag can be done without using a list. However, in the event you're adding multiple Tags, they would need to be in a list, so using a list even for one Tag is a good habit to be in.

Thanks for all the helpful info in this thread. Here is my modified solution. It is a bit more robust in that it will open the DB if it is not open already. It will also be tidy; if you didn’t have the DB open before, you probably don’t want it open after, so it closes the DB

set databaseOpen to true
set DB to "Testing"
set dest to "/Hazel/AT&T Wireless"

tell application id "DNtp"
	if DB is not in (name of databases) then
		set databaseOpen to false
		open database "/Users/paul/Documents/DEVONthink/Testing.dtBase2"
	end if
	
	set destinationGroup to get record at dest in database DB
	set newRecord to (import theFile to destinationGroup)
	set tags of newRecord to {"jim"}
        -- Commented out as I am going to let Hazel take care of it
	  --if (exists newRecord) then tell application "Finder" to delete theFile
	
	if not databaseOpen then
		close database DB
	end if
end tell

Nice to see you working on some AppleScript. macOS automation is a fun and powerful thing! :smiley:

Are these features already available in DT3?

Yes. Please review the built-in Help > Documentation > Automation chapter, revised and rewritten for what DEVONthink 3 brings to the table!

1 Like

Thank you, I will study it.