Building Trees for intersecting tags

I often have tag groups that look like this:

separate trees.jpg

I thought it might be interesting to have an intersection of the two tag groups for browsing and exploration for a result like this:

intersecting trees.jpg

This little script creates a new directory structure of the intersection of the two tag groups. The files are replicants so the structure is easily deleted or recreated.

tell application id "DNtp"
	set theResult to display dialog "Enter the names of two tag groups separated by a semi colon:" default answer "" with title "Tree builder"

	set oTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ";"
	set theResult to every text item of text returned of theResult
	set AppleScript's text item delimiters to oTIDs
	set firstGroup to children of (create location "/Tags/" & item 1 of theResult)
	set secondGroup to children of (create location "/Tags/" & item 2 of theResult)

	repeat with theFirst in firstGroup
		set firstname to name of theFirst as string
		repeat with theSecond in secondGroup
			set secondName to name of theSecond as string
			set theFiles to lookup records with tags {item 1 of theResult, item 2 of theResult, firstname, secondName}
			if theFiles is not {} then
				set theLocation to create location item 1 of theResult & " of " & item 2 of theResult & "/" & name of theFirst & "/" & name of theSecond
				repeat with theFile in theFiles
					replicate record theFile to theLocation
				end repeat
			end if
		end repeat
	end repeat
end tell

Until DT doesn’t come up with the so badly needed feature to filter tags, and choosing to create a Spotlight index in DT’s database properties doesn’t make tags availble out of DT, this script is useful indeed. Thank you.

It was really just a little experiment. I would like to take the idea of tag exploration and link discovery further but its too big a task for applescript (Ammonite is a great example for its integration with DT). There has been quite a few forum threads on the visualisation of data from DT. I am playing around with Neo4j again. Graph databases appear to have so much potential but getting value for effort is harder than it seems.

For the moment I will probably just build this script out a little to make building trees with different boolean operators easier.