Problem with script

Using the script: Export/listing, I have started getting the following message.

sh: -c: line 1: unexpected EOF while looking for matching `"
sh: -c: line 2: syntax error: unexpected end of file

Can someone explain the problem?

Many thanks.


which filename and which destination folder did you use? Because I couldn’t reproduce this issue over here.

My database is called Research, so the script suggests Research.txt and I’m saving to the desktop.

It has been working fine, but problems started occurring recently. The script will progress satisfactorily and then hang, producing the error message above.


Did you change anything recently, e.g. use a different username or account?

No - it’s a longstanding d’base.

The only thing, that may or may not be significant, is that I did a lot of tidying up, mainly renaming items to more sensible titles, and I often used the contextual menu ‘set title as’ after selecting text.

However, the script seems to run fine through most folders, getting stuck eventually with its error message. At the moment it’s sticking over a folder with email messages transferred from’mail’ - but these are plain text and have not been retitled.

Thanks for help.

How many contents/groups (see File > Database Properties…) does the database contain? Maybe it’s just too much data for this simple script.

It’s indeed an overflow, here’s a revised and more stable version of the script (please note that the script is now using UTF-16 instead of UTF-8 encoding)

-- Create Listing.
-- Created by Christian Grunenberg on Sun Jul 24 2005.
-- Copyright (c) 2005-2006. All rights reserved.

using terms from application "DEVONthink Pro"
	tell application "DEVONthink Pro"
			if not (exists current database) then error "No database is open."
			set theDatabase to the current database
			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 thePath to POSIX path of theFile
			if thePath does not end with ".txt" then set thePath to thePath & ".txt"
			set sysInfo to system info
			set writeFile to open for access file ((thePath as POSIX file) as string) with write permission
			set eof writeFile to 0
			if ((CPU type of sysInfo) as string) contains "PowerPC" then
				write (ASCII character 254) to writeFile
				write (ASCII character 255) to writeFile
				write (ASCII character 255) to writeFile
				write (ASCII character 254) to writeFile
			end if
			write (theListing as Unicode text) to writeFile
			close access writeFile
			-- do shell script "echo " & quoted form of theListing & ">" & quoted form of thePath
			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
				on error number error_number
					if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
				end try
			end if
		end try
	end tell
	on createListing(theseRecords, theTabs)
		local this_record, this_type, this_listing, this_name
		set this_listing to ""
		tell application "DEVONthink Pro"
			repeat with this_record in theseRecords
				set this_name to (name of this_record as string)
				set this_listing to this_listing & theTabs & this_name & return
				set this_type to type of this_record
				if this_type is group or this_type is sheet then
					step progress indicator this_name
					set this_listing to this_listing & my createListing(children of this_record, theTabs & tab)
				end if
			end repeat
		end tell
		return this_listing
	end createListing
end using terms from

Thank you - that works a treat.

For anyone who is interested, the listing will open in Omnioutliner, and can also be sent to Tinderbox, if you want to make a visual map of a database.


It’s also possible to export the structure of a database as an OmniOutliner file (see File > Export > as OmniOutliner document…) which can be imported by OmniGraffle to create a visual map.

An export to OO includes all the text in folders and items. Export listing via the script assembles the file names only within their folder structure. Very elegant - useful sometimes for reorganising a big database.