Is Hazel still real useful for using with Devonthink?

Just curious if anybody is still using this combo and if it is useful at the end of 2022 here.

I use CleanMyMac to help delete programs thoroughly. But finding files and organizing them and that kind of thing might be useful to me.

What I think would be really useful is if it could figure out where a lot of the PDFs that I have should go. Which database.

Thanks.

In my experience the combination of Hazel and DEVONthink allows you to develop really sophisticated workflows for manipulating files. I would not wish to be without either app.

In passing, and expressing a purely personal opinion, CleanMyMac does not fall into that category of app. I’m exceptionally wary of apps that purport to "clean” things. Where appropriate I rely on Hazel, again, to delete unwanted linked files when deleting an app (after rather careful consideration of the list of files that will also be deleted).

Stephen

7 Likes

Can you identify some Hazel use cases?
I use a combination of AppleScript and Devonthink

1 Like

By all means: one is, of course, in the link in my post. Here are a few others:

  1. I archive my DEVONthink databases weekly by way of additional backup (and use a script to do so). Hazel ensures that only the last two backups remain in the backup folder on my Mac (i.e., it prunes any backup older than the last two—which is what I want). (I have other apps—like Capture One—that create regular automatic backups and use Hazel in the same way to ensure I keep only the two most recent backups.)

  2. I use Hazel to move classical music downloads to a specific folder for processing.

  3. Specifically, in the context of DEVONthink, Hazel renames many different downloaded bills and statements and transfers them to the DEVONthink inbox for further automatic processing in DEVONthink.

Stephen

5 Likes

Along with @Stephen_C, I would not want to be without Hazel. Not everything I do with Hazel is related to DEVONthink, but when it is I find it more convenient to use Hazel Rules to interrogate incoming files’ content and take decision on name, etc. No jumping through hoops for me with AppleScript, JavaScript, or Python. I do have some more sophisticated stuff based on Python called from Hazel. I have Hazel so I use it.

Here is a document which describes the setup (written a while back).

Inspired by @Stephen_C (or perhaps reminded!), I also automatically make weekly backup “archive” of all databases into Zip Files. I’ll setup a Hazel rule to delete all but the last two. Been wanting to do that for some time!

DEVONthink and Hazel Productivity.pdf (1013.7 KB)

5 Likes

Thanks everyone for your responses. Hopefully this will be a general response back to everybody.

Based on these responses I will be picking up Hazel today.

I really appreciate the help. What a wonderfully supportive community.

1 Like

I’m trying to do something similar with Hazel (keeping only the last archive of the day)–would love to see your workflow.

I use Hazel to copy newly (and legally!) downloaded eBooks, photos, and music from my MBP to the appropriate family media server locations after I have cleaned up metadata.

I use this feature extensively! Any statement or bill that hits my download folder gets scanned by Hazel, renamed, and added to DT Global Inbox where I can have some Smart Rules do further processing and filing–there are likely ways to do this all in DT, but some of these workflows pre-date my switch from EN to DT and they just work.

I also use Hazel to run Zowie every time I add a new reference to Zotero to make it easier to work with journal articles in both Zotero and DT.

On the assumption you’re referring to the Hazel part you just need a very simple Hazel rule for each of the archived databases, along the following lines (and linked, of course, to your backup/archive folder):

If you were also referring to seeing the archive script I can of course post that if you need it.

Stephen

2 Likes

Sure, if you’re inclined…This is giving me some fine ideas…

Note: this is based upon the Daily backup archive script included with DEVONthink so much of the credit for the script goes to @cgrunenberg.

-- First set the path of the folder to which you wish to backup
property pbackup_path : "/Users/[your user name]/Documents/DevonThink/Backups/"

tell application id "DNtp"
	
	-- We are going to set the date format to add to each archived database
	set this_date to do shell script "date +%Y-%m-%d-%H-%M-%S"
	set all_databases to every database
	
	try
		display dialog "Create backups of all open databases?" with title "Backup all open databases" buttons {"Cancel", "Continue"} default button {"Continue"} with icon 1
		
		-- Set a general progress indicator
		show progress indicator "Weekly backup of all open databases…" steps count of all_databases
		
		repeat with this_database in all_databases
			set this_name to name of this_database
			
			-- We use the backup path property here
			set this_archive to pbackup_path & this_name & " " & this_date & ".dtBase2.zip"
			
			with timeout of 3600 seconds
				
				-- Show which database we're processing
				step progress indicator this_name as string
				
				if (verify database this_database) is not 0 then error "Database --" & this_name & " is damaged."
				
				if not (optimize database this_database) then error "Optimisation --of database  " & this_name & "failed."
				
				if not (compress database this_database to this_archive) then --error "Backup  of database " & this_name & "failed."
				end if
			end timeout
		end repeat
		hide progress indicator
		
		-- Show an alert when it's all done
		display alert "Backups of all open databases complete."
		
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then log message "DEVONthink:" & error_message
	end try
end tell

Stephen

2 Likes

Just one question: Why do you introduce the variable all_databases instead of simply referring to databases, which is a property of the Application object in this case? I’d probably write
repeat with this_database in databases
but maybe that’s not possible for some reason?

Pass… :blush: If I recall correctly I took that part of the script from someone else’s script on here. You should know by now that I program blindly and if something works I leave it well alone! :grin:

Apologies for inadequacies!

Edit: for anyone interested, this is the original thread from which my script was developed.

Stephen

2 Likes

personally, I would love for DT to implement the flexibility of Hazel’s rules. I believe DTS rules are more complex to implement and not as flexible/powerful.

For example, I have not been able to find a way to classify files in DT by Month/ day using a short month name for the folder using rules. I am sure it’s doable by using AppleScript. Most of the work I have to do in DT is classifying stuff manually.

I have about 60 Hazel rules that automatically identify and re-name all statements that I receive regularly, such as for banks, utilities, etc. It then sorts them directly into the appropriate DEVONthink group, which I specify in the embedded AppleScript when setting up each rule. The Hazel rule generally looks like the following (varying, of course, depending on the formatting of each statement):

… and the AppleScript looks like this:

set _theID to "AFB4D3B8-F8B3-4C6C-9925-10622CA3B7F0"

tell application "Finder"
	set _path to (the POSIX path of theFile as string)
	set {_name, _extension} to {name, name extension} of theFile
	set _name to text 1 thru -((count _extension) + 2) of _name
end tell

tell application id "DNtp"
	set theGroup to get record with uuid _theID
	set theImport to import _path name _name to theGroup
end tell

This is a modified version of a script I found on these forums long ago, and am sorry to have lost track of who first developed it (possibly the mighty korm?). The main change I recall making was to put _theID up at the top, which makes it easier when setting up the rule to paste in the group UUID (which I obtain by selecting Copy Item Link and deleting the x-devonthink-item:// part).

I find this setup very useful, and have not yet found a way to replicate the whole process using DEVONthink alone. The main thing I can’t figure out is how to extract the date from the PDF contents as robustly as Hazel allows. If anyone can tell me how to do so, I would appreciate it :slight_smile:

And if anyone has questions about my setup above, I’d be happy to try to help.

1 Like

Excellent, and I do pretty much same (although after tagging and name a document and into DEVONthink I don’t much care about setting it into a complex hierarchical Group or folder). Probably got the idea from this forum also! Agree that Hazel quite robust and powerful for handling dates. Nothing wrong with exploiting the the power of the pair–Hazel and DEVONthink. :wink:

1 Like

I do the same with a single smart rule and a JavaScript script in DT.

I described the script here some time ago. Searching for „Hazel maybe“ should tell you more.

1 Like

Since we’re talking about Hazel and filing stuff… I too have both Hazel and DEVONthink. However, I haven’t used them together — I prefer to file things in DT in a carefully organized fashion.

The thing I do use Hazel for is trashing files. I have a temporary folder for random work in progress, and I have Hazel watch that folder and my Downloads folder. Once a file has been there for 2 weeks, Hazel uses Finder labels to turn it red. After another 2 weeks, Hazel puts it in the trash.

This will probably sound like a crazy way to use software, but honestly it has been life-changing. No more folders full of stuff I can’t remember what it was for and don’t dare delete. If it’s important and needs to be kept I put it in the right place. If not, I forget about it. I just wish I could do the same with paper mail.

1 Like

How is using Hazel precluding your use of DEVONthink in your “carefully organised fashion”. Just curious.

@chrillek

Is the script at

https://bru6.de/jxa/docs/automating-applications/devonthink/OCR%20and%20move%20to%20group%20for%20DT.js

the current version? Or is there an updated version?

@dgbeecher

Can you explain, what this block does? I’m not very familiar with AppleScript:

tell application "Finder"
	set _path to (the POSIX path of theFile as string)
	set {_name, _extension} to {name, name extension} of theFile
	set _name to text 1 thru -((count _extension) + 2) of _name
end tell