Quick triage of group contents

A script for rapidly sub-dividing the contents of a group.

Throughout the day I pause to send quick thoughts (in the form of text files) to a particular group.

The number of files in this group can get large, and I like to be able to do a quick triage of its contents into sub-groups, before moving the records on elsewhere.

If you select a DT group and run this draft script, it will loop through all the content records at the top level of the group, displaying each time the name of a record, and offering to move it into one of the existing sub-groups of that group.

(If there is no suitable sub-group, it can create a new-group, prompting you for a name, and moving the record into that new group).

I find that it allows for fairly rapid triage.

(Note that DT may not refresh its display of the group contents until you exit the script).

-- QUICKLY SUBDIVIDE THE CONTENTS OF THE SELECTED GROUP INTO SUB-GROUPS

property pTitle : "Triage: "
property pVer : "0.6"

property pstrOpen : "View contents"
property pstrNewGroup : "Make new sub-group"
property pTab : "	"

on run
	tell application id "DNtp"
		set oFolder to current group
		set strFolder to name of oFolder
		
		-- LOOP THROUGH RECORDS OF GROUP, ALLOCATING THEM TO SUBGROUPS
		--	AND CREATING NEW SUB-GROUPS ON THE FLY, WHERE NEEDED
		
		set varChoice to true
		set winView to missing value
		repeat while varChoice
			-- STOP IF THERE ARE NO MORE CONTENT RECORDS TO BE ALLOCATED TO SUB-GROUPS
			set refChildren to a reference to (children of oFolder where kind ≠ "Group")
			set lngChildren to count of refChildren
			if lngChildren < 1 then return
			
			-- CHOOSE THE NEXT RECORD TO DEAL WITH
			set oRec to first child of oFolder where kind ≠ "Group"
			
			-- LIST THE AVAILABLE SUB-GROUPS
			set refGroups to a reference to (children of oFolder where kind is "Group")
			set lstGroupNames to name of refGroups
			set lngGroups to count of lstGroupNames
			
			set lngDigits to (length of (lngGroups as string))
			
			set lstIndex to {}
			repeat with i from 1 to lngGroups
				set end of lstIndex to my PadNum(i, lngDigits) & pTab & item i of lstGroupNames -- tab
			end repeat
			
			-- AND THE OPTION TO CREATE A NEW SUB-GROUPS
			set lstIndex to {pstrOpen, pstrNewGroup} & lstIndex
			if (count of lstIndex) > 2 then
				set strDefault to item 3 of lstIndex
			else
				set strDefault to item 2 of lstIndex
			end if
			
			-- DISPLAY THE NAME OF THE CURRENT RECORD, AND GET THE USER RESPONSE
			set varChoice to choose from list lstIndex default items strDefault with prompt "• " & (name of oRec) as string with title pTitle & strFolder
			if varChoice is false then return
			set strChoice to first item of varChoice
			
			-- EITHER MOVE THE RECORD TO THE SELECTED SUB-GROUP
			set oMoved to missing value
			if strChoice ≠ pstrNewGroup then
				if strChoice ≠ pstrOpen then
					-- Move record to existing group
					set {dlm, my text item delimiters} to {my text item delimiters, pTab}
					set lngChoice to (first text item of strChoice) as integer
					set my text item delimiters to dlm
					
					set oGroup to item lngChoice of refGroups
					set oMoved to move record oRec to oGroup from oFolder
					try
						if winView is not missing value then close winView
					end try
				else
					set winView to open window for record oRec
				end if
			else -- OR MOVE IT TO A NEWLY CREATED SUB-GROUP
				-- create a new group and re-enter loop
				set strNewGroup to ""
				tell (display dialog "New Group" default answer "" with title pTitle & strFolder)
					set strNewGroup to text returned
				end tell
				if strNewGroup ≠ "" then
					--oFolder
					tell oFolder to set oNewGroup to create location (location) & (name) & "/" & strNewGroup in database
					set oMoved to move record oRec to oNewGroup from oFolder
				end if
				try
					if winView is not missing value then close winView
				end try
			end if
			
			-- AND SELECT THE NEXT RECORD (IF THERE IS ONE)
			-- BEFORE REPEATING THE LOOP
			if oMoved is not missing value then
				set refChildren to a reference to (children of oFolder where kind ≠ "Group")
				if (count of refChildren) > 0 then
					set oRec to first item of refChildren
				else
					exit repeat
				end if
			end if
			set varChoice to true
		end repeat
	end tell
end run

-- NUMERIC STRING OF FIXED WIDTH - PADDED WITH LEADING ZEROS
on PadNum(lngNum, lngDigits)
	set strNum to lngNum as string
	set lngGap to (lngDigits - (length of strNum))
	repeat while lngGap > 0
		set strNum to "0" & strNum
		set lngGap to lngGap - 1
	end repeat
	strNum
end PadNum

Nice idea - what does this do that See Also & Classify doesn’t? Over here, I find that See Also & Classify works well when I’m triaging a given database’s inbox (or other collection point).

For me, this approach gives a bit more speed and cognitive focus - allows me to hold a smaller set of options in mind, and move through the list quite fast.

i.e. a more industrial approach - less nuanced, but faster :slight_smile: particularly when the SA & C suggestions lack edge.

(Right now, for example, I need to move quite quickly through 154 more records, and I want to give them a quick first order triage in relation to a particular project. A more delicate and considered allocation can happen later, if necessary).

(This also integrates triage with very rapid creation of new groups - especially useful when the categories are still evolving, and SA & C doesn’t have much to work on).

Added a command to the triage dialogue - view contents of the record.

Robin, I’m getting a couple of anomalies:

Here’s an example of the structure

Top group
– Sub 1
– Sub 2
– Sub 3

If I run the script on “Top Group”, select “Make new sub-group”, the new group is created at the root level, not under “Top Group”. Is this intended?

If I cancel out the script, the next time it is run it (again, selecting “Top Group”) it shows the selected item as “Sub 2” (i.e., the second sub group, regardless of name) and not the first record in “Top Group”.

I have ScriptDebugger logs of the second item if you wish. Let me know where to send them. (The logs use the actual structure of my test data - not the example names given above.)

Yes - well caught - an earlier version created the group in the location of the parent folder, rather than the location & name.

You should find that the current version (above) fixes that.