I’m trying to export the names of the contents os a database using the script provided (UTF-8) and although it does create a .txt file, when I open it (in TextEdit) all I see are Chinese characters.
I also tried to setup the alternative script (UTF-16) given by Christian (devon-technologies.com/phpBB … ht=listing) and the result was the same: Chinese characters.
Hmmm… the AppleScript Unicode handling on Intel Macs does not work as expected. Here’s a fixed script:
tell application "DEVONthink Pro"
activate
try
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 writeFile to open for access (thePath as POSIX file) with write permission
set eof writeFile to 0
write (ASCII character 254) to writeFile
write (ASCII character 255) to writeFile
write (theListing as Unicode text) 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
try
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
It’s always a pleasure to help customers, especially if a script can do the job. And to be honest - I’ve never done any scripting before DT Pro but the power of its AppleScript suite makes a lot of stuff possible and can automate many tasks.