A question re "Summarize Highlights"

OK, I got curious, and had to see if I could script this! I started out with the idea to re-create the “summarize highlight” command, but make it work for any bolded text (since I use that for my headings). I ended up making a “jump to heading” script instead. It looks for all paragraphs that are bolded, and makes a list of them. You can then select one of the headings and your cursor will jump to it.

Here’s what it looks like running:

It’s a pretty clunky code, and a slow script, so I don’t know how useful it is. But it was fun to figure out! Maybe someone else can do better…?

-- Test script: Jump to headings (bolded text) in document
-- Daniel Sroka, 2019-11-01

tell application id "DNtp"
	try
		set itemURL to get the reference URL of (item 1 of (selection as list))
		tell text of think window 1

			set theList to {}
			set thePos to {}
			set paraCount to 0
			
			repeat with thisParagraph in every paragraph
				set len to the number of characters of thisParagraph
				if (font of thisParagraph contains "Bold" and len > 1) then --only finds paragraphs that start bold
					if len > 30 then
						set thisHeading to characters 0 thru 30 of thisParagraph
					else
						set thisHeading to thisParagraph
					end if
					set end of theList to thisHeading as text
					set end of thePos to paraCount
				end if
				set paraCount to paraCount + 1
			end repeat
		end tell
		
		set theChoice to (choose from list theList with prompt {"Choose which heading to jump to: "} default items "" OK button name "Go To") as string
		set choiceNum to my list_position(theChoice, theList)
		set choicePos to item choiceNum of thePos as text
		set itemURL to itemURL & "?reveal=1&line=" & choicePos as string
		open location itemURL
		
	end try
end tell

on list_position(this_item, this_list)
	repeat with i from 1 to the count of this_list
		if item i of this_list is this_item then return i
	end repeat
	return 0
end list_position