A group merge view would be handy

This script creates/updates a Transclusion record for the group’s Markdown records and selects or opens it in a new window.

From help:

Attaching a triggered script

  • Select the item you want to attach a script to.
  • Select Tools > Get Info or Tools > Inspectors > Generic.
  • Click the down arrow next to Script and choose Select. Note the script can be located anywhere, but it must remain in that location for the script to trigger. For convenience, you can create a folder for them in ~/Library/Application Scripts/com.devon-technologies.think3/Menus.
-- Triggered script - Create transclusion for current group's Markdown records

-- Setup: Click "script" in a group's info inspector. Select path

property selectTransclusionRecord : true -- if false Transclusion record opens in a new window

on triggered(theGroup)
	tell application id "DNtp"
		try
			set theResults to search "kind:markdown comment:\"Transcluded group contents\"" in theGroup
			if theResults ≠ {} then
				set theTransclusionRecord to item 1 of theResults
			else
				set theTransclusionRecord to create record with {name:"_Transclusion - " & (name of theGroup), type:markdown, source:"", comment:"Transcluded group contents"} in theGroup
			end if
			
			set theChildren_ReferenceURLs to reference URL of children of theGroup whose type = markdown and comment is not "Transcluded group contents"
			if theChildren_ReferenceURLs = {} then error "This group doesn't contain Markdown records"
			set theTransclusionRecord_Source to "{{" & my tid(theChildren_ReferenceURLs, "}}" & linefeed & "{{") & "}}"
			set plain text of theTransclusionRecord to theTransclusionRecord_Source
			
			if selectTransclusionRecord then
				set selection of think window 1 to {theTransclusionRecord}
			else
				open window for record theTransclusionRecord
				activate
			end if
			
		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 triggered

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid

@cgrunenberg By the way, I know this has been asked several times and will probably not be implemented but it would be very very useful if we could set some window properties. Especially setting the state of the preview, the sidebar and the inspector would be very handy (at least whether they are shown or not). Bonus points if we could open the inspector to specific tabs :wink: Thank you very much for all the new AppleScript stuff, it’s amazing that almost everything users asked for is implemented after some months.

2 Likes