set "see also" flag based on smart groups

Why this script

Since I started using DT, I’ve wanted the ability to easily select sets of documents to use for “see also.” As an example, my database contains a few thousand documents that I’ve written myself, and a few thousand documents that I’ve collected from other sources. Sometimes I want to use “see also” across the entire database, but sometimes I want to use it only on the documents that I’ve written, or only on documents that other people have written. DEVONtech is supposedly working on “see also” across databases, but in the mean time, this script will have to do.

What it does

This script lets you switch between sets of documents for “see also”. Just set up a smart group to match the documents you wish to use for “see also”, run the script, and now only those documents are “see also”-able :slight_smile:

How it works

It relies on two smart groups: “All Documents” (kind is any document) and “see also” (your custom smart group that matches documents you want to enable “see also” on). The script first disables “see also” for every document in the system, and then enables it for the ones that match your “see also” smart group. You can also permanently exclude documents from “see also” by tagging them with “no see also”.

How I use it

I have one primary content database. Every document has one of two tags: “me” or “not me”. I have smart groups set up to match those two tags. If I want to “see also” across my documents only, I duplicate the “me” smart group and rename it to “see also.” Same goes for “not me”, and if I want to “see also” across all documents, I duplicate & rename the “All Documents” smart group.

Other stuff

  • I wrote this with the intention of being useful, not to delete your files or eat your babies. But I can’t promise that those bad things won’t happen. Use at your own peril, and all that.

  • The script takes between 20-40 seconds to run on my machine, with a database containing 6k documents, totaling 3.3GB.


try
	tell application "DEVONthink Pro"
		repeat with this_record in (children of (get record at "All Documents" in current database))
			set exclude from see also of this_record to true
		end repeat
		
		set this_selection to children of (get record at "see also" in current database)
		if this_selection is {} then error "Please select some contents."
		
		repeat with this_record in this_selection
			set exclude from see also of this_record to false
		end repeat
		
		repeat with this_record in (lookup records with tags {"no see also"})
			set exclude from see also of this_record to true
		end repeat
	end tell
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" message error_message as warning
		on error number error_number
			if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
		end try
	end if
end try