Workaround for "filtering" See Also and Classify inspectors temporarily with one click

Hi,

I’ve begun using a workaround that allows temporarily only showing specific types of items or groups in the See Also & Classify inspectors, and thought I’d share this here as I find it quite useful.

Purpose of filtering these inspectors

For example, if I’m working with my Zettelkasten (atomic notes) I may only be interested in See Also showing other notes that are part of the Zettelkasten.

Another example: When reading a blog article I downloaded, I may be interested only in other similar blog articles rather than academic papers that are similar.

How to use the workaround after setup is complete

In DevonThink, whenever you are about to go into a certain workflow, consider what would be the most relevant See Also scope. Press the hotkey, which you applied to all of the KBMaestro macros. Then select the desired scope from the “popup menu” that now displays the titles of the different macros you created during setup. Wait a couple seconds while DT processes the smart rules and re-select the item you’re looking at for the inspectors to reflect the new scope.

Screenshot 2022-04-09 at 09.15.24

Setup Instructions

Here’s an example for the See Also inspector. To achieve the same for “Classify”, one would simply exchange “See Also” in the script for “Classify”.

First, you need a Smart Rule with scope “any document”, which executes a script (credit @pete31) to exclude these items from See Also. The trigger should be set to On Demand (explanation follows below).

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			repeat with thisRecord in theRecords
				set exclude from see also of thisRecord to true
			end repeat
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end performSmartRule

Then, set up multiple smart rules, each with different scope for those items to include (e.g. only blog articles, only books with a certain tag etc.). Set this Smart Rule to “On Demand”. Based on this scope, the following script is executed to set “Exclude from See Also” to false, i.e. to include items that are in scope.

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			repeat with thisRecord in theRecords
				set exclude from see also of thisRecord to false
			end repeat
			
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end performSmartRule

Now, set up a new keyboard maestro macro (“Execute AppleScript”) and use the following code (again credit @pete31) to firstly trigger the smart rule that excludes all items from See Also (modify the text in quotes to reflect the exact name of your smart rule in DevonThink):

tell application id "DNtp"
	perform smart rule name "Exclude all documents from See Also"
end tell

Add a pause of a couple seconds and then add a second “Execute AppleScript” action to trigger one of the smart rules, which includes items of a certain scope. Set a hotkey trigger.

The trick now is to duplicate the KBMaestro macro and, in the duplicate, to modify the second “Execute Applescript” action to trigger a different smart rule, which includes a different scope of database items in See Also. Modify the title of the macro to reflect this new scope, e.g. “See Also: Include only articles” and set the same hotkey trigger that was used in the first one.

Add as many duplicate macros as needed to reflect all different See Also “filters” needed for your use case.

Looking forward to any feedback and suggestions for further refining this workaround :slight_smile:

Performing this for all contents in all databases via a script in the Scripts menu like this can be a lot faster (assuming that the above rule script is also applied to all contents in all databases):

tell application id "DNtp"
	set exclude from see also of contents in databases to true
end tell

That’s currently 100 times faster than using a loop for each record, in the next release the difference will be even larger.

1 Like

Thank you very much, this definitely processes faster!

For my use case, I’m partial to being able to trigger the smart rules via a keyboard shortcut and select one of several “filter” options.

So I’m triggering this via KB Maestro instead of the script menu. I also changed the scope to only run on a specific database.

tell application id "DNtp"
	set exclude from see also of contents in database "SOURCE FILES_1.3" to true
end tell

A related but more general question : Is my understanding correct that it is impossible for two smart rules to run in parallel, i.e. once triggered the smart rule completes all processing before any other smart rules (regardless of the trigger) run?

That’s correct, smart rules are queued and processed one after another.

1 Like