Processing tagged items in Group Tags: how to proceed to next item?

I’ve got a folder “00 Processed” where my items end up before tagging / classifying. “00 Processed” is an indexed folder, excluded from tagging and thus a Group Tag. My workflow is as follows:

  1. I use the pane “See Also & Classify” to classify items. Often I select multiple groups to classify to, which means the item will replicate instead. This prevents moving the item from the path(!) for the folder “00 Processed”. The location group does change. Because I want my classified items inside one of the target groups, I use smart rules (see below) to move the item to the location group and out of “00 Processed”

  2. Sometimes the classify options I’m looking for don’t show up. I then manually add the tags I want the item replicated to. I remove the “00 Processed” tag to make sure the item is not in the “00 Processed” group anymore and also use smart rules to make sure the path/file doesn’t stay in the “00 Processed” folder.

The workflow works quite well. I had to figure out a way to preserve original tags (e.g. added when clipping) with classifying. I’m doing this by writing the tags on importing to a custom meta data originaltags as a comma-separated list.

Also I had to figure out how to get DT to show the next item after classifying. When using a move record Applescript command in an “On Classifying” smart rule, this would end up in a “No selection” screen - instead of classifying progressing to the next item. Interestingly enough I found a workaround: it does work if I use an “On Replicating” smart rule with the same move command and call that rule from the “On Classifying” smart rule.

There’s one aspect that doesn’t work well for me yet:

When using the tagging approach under (2) whenever an item is automatically moved from the “00 Processed” folder I end up with a “No Selection” text in the viewer window. Which makes sense of course, because the selected item was just moved from view.

Is there a way to move to the next item when I’m in the “00 Processed” group and after removing the “00 Processed” tag? Or is there another work around, e.g. through scripting or using another selection (a Smart Group?) to circumvent this behavior? My goals is I can ‘keep tagging’ through all of the documents in the "00 Processed folder.


Smart rule "On classifying"

2022-03-11 CleanShot CleanShot 14.10.41

use AppleScript version "2.4" -- Yosemite (10.10) or later
use script "RegexAndStuffLib" version "1.0.7"
use scripting additions

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set recordTags to tags of theRecord
			set originalTags to get custom meta data for "originaltags" from theRecord
			if originalTags is not missing value then
				set originalTagsList to split string originalTags using delimiters ","
				set tags of theRecord to (recordTags & originalTagsList)
			end if
		end repeat
	end tell
end performSmartRule

Smart rule "On replicating / tagging"

2022-03-11 CleanShot CleanShot 14.11.39

use AppleScript version "2.4" -- Yosemite (10.10) or later
use script "RegexAndStuffLib" version "1.0.7"
use scripting additions

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set theTags to tags of theRecord
			set theLocationgroup to location group of theRecord
			move record theRecord to theLocationgroup
			set tags of theRecord to theTags
		end repeat
	end tell
end performSmartRule

This handler could work

-- Demo - Move focus to next item

tell application id "DNtp"
	try
		activate
		
		repeat 10 times
			my moveFocus()
			delay 1
		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

on moveFocus()
	tell application "System Events"
		tell process "DEVONthink 3"
			try
				key code 125
			end try
		end tell
	end tell
end moveFocus

GUI scripting shouldn’t be relied on. Just saying.

I’m even willing to go with GUI scripting if needed. But the challenge is more ‘within’ DT. When an item gets moved away using Classify DT does what I hope: move to the next item. In any other circumstance if an item is ‘gone’ (moved) DT doesn’t know what to do and shows “No selection” in the viewer window.

Maybe a preference could be added to decide what to do if the current viewed document is moved - a bit similar to the “reveal” setting?

@pete31’s suggestion partly works - I would also have to Ctrl-Tab to the file overview. I was thinking about something else, but not sure I could make this work, a smart rule when tagging

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set allRecords to children of root of viewer window 1
			set theCount to 1
			repeat with checkRecord in allRecords
				if id of theRecord ≠ id of checkRecord then
					set theCount to theCount + 1
				else
					exit repeat
				end if
			end repeat
			
			set theTags to tags of theRecord
			set theLocationgroup to location group of theRecord
			move record theRecord to theLocationgroup
			set tags of theRecord to theTags
			
			if theCount ≠ 1 then set theCount to theCount - 1
			set selection of (viewer window 1) to {item theCount of allRecords}
		end repeat
	end tell
end performSmartRule

Considering this would only work for the “Unsorted” order. There’s a problem because the On Tagging trigger fires when I press Return after removing the “00 Processed” tag and so before I can calculate the current position.

But maybe this could work: instead of pressing Return after tagging I could create a shortcut-triggered script (e.g. via Fastscripts or Keyboard Maestro) which:

  • Runs the first part script above (instead of the smart rule) - calculate current position
  • Move the item
  • Run the second part of script (set the current selection)

Thinking about it: I could also not use the index, but rather the id of the real next item. Than sorting wouldn’t matter. It could also make my life easier as it could also remove the “00 Processed” tag instead of me doing it manually.

Any suggestions?

Our preferences are already very, very full.
And bear in mind, you are doing something very custom to your own process and way of thinking.

1 Like

Thanks I understand that ofcourse, I’ll investigate a bit further. A related question: is there a way (shortcut?) to focus on the tag bar underneath the document?

Control-Return

1 Like

Thanks @BLUEFROG!

For everyone coming to this thread later and looking for a way to keep ‘processing’ tags without losing focus (sorry @BLUEFROG - it requires a bit of GUI scripting ;-))

I’ve created this script under a Command-Return shortcut in Keyboard Maestro. Still looking for a way to check if I’m already in the tag bar (so I can make the ‘first’ Command-Return focus on the tag bar), but can’t yet find a way to do that.

use AppleScript version "2.4" -- Yosemite (10.10) or later
-- use script "RegexAndStuffLib" version "1.0.7"
use scripting additions

tell application id "DNtp"
	activate
	
	set currentClipboard to the clipboard
	set the clipboard to ""
	
	set theRecord to first item of (selection as list)
	
	tell application "System Events"
		tell process "DEVONthink 3"
			tell menu "Edit" of menu bar 1 to click menu item "Tags..."
			keystroke "a" using command down
			keystroke "c" using command down
			tell menu "Go" of menu bar 1 to click menu item "Move Focus to View"
			tell menu "Go" of menu bar 1 to click menu item "Next Document"
			set theCopiedTags to the clipboard
		end tell
	end tell
	
	-- If using RegexAndStuffLib uncomment this
	-- set theCopiedTagsList to join strings theCopiedTags using delimiter "\n"
	set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "\r"}
	set theCopiedTagsList to text items of theCopiedTags
	set AppleScript's text item delimiters to od
	
	set theTags to {}
	repeat with theCopiedTag in theCopiedTagsList
		if theCopiedTag as string is not equal to "00 processed" then
			set theTags to theTags & theCopiedTag
		end if
	end repeat
	
	if (count of theTags) is greater than 0 then
		set tags of theRecord to theTags
	else
		tell application "System Events"
			tell process "DEVONthink 3"
				tell menu "Data" of menu bar 1 to click menu item "Classify"
			end tell
		end tell
	end if
	
	set the clipboard to currentClipboard

	tell application "System Events"
		tell process "DEVONthink 3"
			tell menu "Edit" of menu bar 1 to click menu item "Tags..."
		end tell
	end tell
end tell

No worries. It’s there to be used so it’s a choice you can make. Just note it’s always been fiddly and somewhat unreliable. :slight_smile: