tag names listed when exporting multiple documents

I realise I can include document names when I export multiple documents as text, rtf, etc. (Something I’ve only just discovered much to my embarrassment.) What I would find particularly useful would be a similar option in the export dialogue box to also list the names of tags associated with each document.

I managed to modify one of Christian’s scripts to do more or less what I wanted. My scripting skills are limited. Suggested improvements welcome.

– Create listing of the selected items instead of all items in a database
– based on
– Create Listing script in Export Folder of DTPO scripts
– Created by Christian Grunenberg on Sun Jul 24 2005.
– Copyright © 2005-2009. All rights reserved.

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
set theSelection to the selection
if theSelection is {} then error “Please select some items.”
set theFile to choose file name default name ((name of theDatabase) as string) & “.txt”

	show progress indicator "Creating Listing..."
	
	--set theListing to my createListing(children of root of theDatabase, "")
	set theListing to my createListing(theSelection)
	set thePath to POSIX path of theFile
	if thePath does not end with ".txt" then set thePath to thePath & ".txt"
	set writeFile to open for access (thePath as POSIX file) with write permission
	set eof writeFile to 0
	
	write theListing to writeFile
	
	close access writeFile
	
	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)
tell application id “com.devon-technologies.thinkpro2”
set tabChar to ASCII character 9
set this_listing to “”
repeat with this_record in theseRecords
set this_name to (name of this_record as string)
set old_delim to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to "; "
set the_tags to tags of this_record as text
set the_text to plain text of this_record
set AppleScript’s text item delimiters to old_delim
set this_listing to this_listing & this_name & return & return & the_text & return & return & the_tags & “.” & return & “======” & return & return
end repeat
end tell
return this_listing
end createListing