Put rtf links to selected group and children on clipboard

This script is a mash-up of 2 or 3 different scripts that korm and Christian have done. (Plus my own little twists)
I wanted to generate an indented list of links that could serve as an index. @korm, I commented out your code for selecting “Whole Database” because I wasn’t sure what would happen if someone used it on a multi-gigabyte database. There must be a limit somewhere for the clipboard!?
An example of the output:

Screen Shot 2013-11-09.jpg

-- Create Listing.
-- Created by Christian Grunenberg on Sun Jul 24 2005.
-- Copyright (c) 2005-2009. All rights reserved.
-- Modified 20130602 to capture only groups
--Modified by @clane47 11_01_2013 to capture only groups to a rich text file
-- Modified by @korm 20131102 to put the listing on the clipboard for pasting elsewhere
-- Additional modification 20131102 to optionally set base group for the listing to the selected group
--Modified 11_08_2013 by clane47 to create a list of links of the selected groups/files
--If you REALLY want the option to generate links to every group and doc in your database,
--then uncomment the code.
--This is mostly a mash-up of some of korm's scripts + a few twists of my own.
--Remember, the result is on the clipboard ready to be pasted into a document.
--In particular though, I like Christian's recursive subroutine!

global o_HTML

tell application id "com.devon-technologies.thinkpro2"
	try
		if not (exists current database) then error "No database is open."
		set theDatabase to the current database
		show progress indicator "Creating Listing..."
		
		--set listScope to button returned of (display dialog "Scope of Group Listing" buttons {"Whole Database", "Selected Group and Children", "Cancel"} default button 1 cancel button 3 with title "Put a Group Listing on the Clipboard")
		--
		--if listScope is "Whole Database" then
		--	my createListing(children of root of theDatabase, "")
		--	set o_RTFLink to (do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" as rich text)
		
		--else if listScope is "Selected Group and Children" then
		set rootGroup to the current group
		my createListing(rootGroup, "")
		set o_RTFLink to (do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" as rich text)
		--else
		--	return
		--end if
		
		hide progress indicator
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

on createListing(theseRecords, theTabs)
	local this_record, this_type, this_listing, this_name
	tell application id "com.devon-technologies.thinkpro2"
		set o_HTML to ""
		repeat with this_record in theseRecords
			set this_name to (name of this_record as string)
			set thisURL to the reference URL of this_record
			set o_HTML to o_HTML & quoted form of (theTabs & "<font face=\"helvetica\"><a href=\"" & thisURL & "\">" & this_name & "</a></font> </br>")
			step progress indicator this_name
			set o_HTML to o_HTML & my createListing(children of this_record, theTabs & "&nbsp" & "&nbsp" & "&nbsp" & "&nbsp" & "&nbsp")
		end repeat
		
	end tell
	return o_HTML
end createListing

VERY clever! Thanks :stuck_out_tongue:

There must be a deep, unmet need in the DEVONthink community for lists, indexes, and cool RTF tricks!

I like lists with bullets, so I made a tiny tweak. You can keep or change to some other bullet character as desired.


set o_HTML to o_HTML & quoted form of (theTabs & "<font face=\"helvetica\">•    <a href=\"" & thisURL & "\">" & this_name & "</a></font> </br>")

@korm, thanks! I wasn’t sure how to add the bullets. And thanks for showing the way in applescript. I never took the time to learn it before I got DTPO, but now I’m having a blast with it. I guess I’ll go try to work on something besides indexes now…… :stuck_out_tongue:

Go clane! Go clane! It’s your birthday… uh… never mind. :smiley:

Happy scripting! Welcome to the club.

Gee, thanks a lot for reminding me of the birthday Jim! Although I’ll be 66 a week from today, I don’t feel a day older than 84. :confused:

Tackling scripting at 65. Very cool. (Not that that’s old.) I know people away younger than you who won’t even attempt it. And you don’t look at day over 50. 8)