How can I get DTPO to export or print a list of all the groups/folders in a database? (I specifically don’t want a listing that includes files, so the Export-Listing Applescript supplied with DTPO wouldn’t be useful to me.)
I’m sure that there’s a very simple answer to this question, but I don’t know what it is. (Nor do I know enough about Applescript to create such a listing.)
Hugh, if you open three-pane view, select View > Expand All, and then select everything in the group panel of that view, you can print that listing or print-to-pdf. The results will not win any beauty contest, but it is workable.
If you find that expanding everything results in more than you want to know (for example, if you have a lot of tags you’ll see each tag group in the expanded list on a separate line) then you can collapse some groups before printing.
After getting your list produced, I find it is faster to get back into my working mode by doing View > Collapse All and adjust the open/shut state of groups, than it is to work backward from the fully-expanded state.
My right hand just reminded me that my left hand made this script a while back to make a listing of just the groups in a database. It is a modified version of Criss’ script that ships with DEVONthink.
-- Create Listing.
-- Created by Christian Grunenberg on Sun Jul 24 2005.
-- Copyright (c) 2005-2009. All rights reserved.
-- Modified 20130602 to capture only groups
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 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
considering numeric strings
if AppleScript's version as string < "2.0" then
write (ASCII character 254) to writeFile
write (ASCII character 255) to writeFile
write (theListing as Unicode text) to writeFile
else
-- Bug of Leopard, encoding is undefined
write theListing to writeFile as Unicode text
end if
end considering
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, theTabs)
local this_record, this_type, this_listing, this_name
tell application id "com.devon-technologies.thinkpro2"
set this_listing to ""
repeat with this_record in theseRecords
set this_name to (name of this_record as string)
set this_type to type of this_record
-- set this_listing to this_listing & theTabs & this_name & return
if this_type is group then
set this_listing to this_listing & theTabs & this_name & return
step progress indicator this_name
set this_listing to this_listing & my createListing(children of this_record, theTabs & (ASCII character 9))
end if
end repeat
end tell
return this_listing
end createListing
Just playing around with this idea. This script does the same thing as Korm’s script, but creates a rich text file in your inbox instead of an external file. If you then select and copy the contents of the file, you can paste it into Curio as either a list or as a mind map. Useful?? I don’t know, but it makes a very nice mind map and it was fun!
-- 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 11_01_2013 to capture only groups to a rich text file
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 theListing to my createListing(children of root of theDatabase, "")
set myGroup to incoming group of theDatabase
set myRecord to create record with {name:"Group List", rich text:theListing, type:rtf} in myGroup
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 this_listing to ""
repeat with this_record in theseRecords
set this_name to (name of this_record as string)
set this_type to type of this_record
if this_type is group then
set this_listing to this_listing & theTabs & this_name & return
step progress indicator this_name
set this_listing to this_listing & my createListing(children of this_record, theTabs & (ASCII character 9))
end if
end repeat
end tell
return this_listing
end createListing
That’s a very clever change to the script, @clane47.
Here’s a riff on your script: instead of making a new RTF record with the group listing, this version puts the listing on the clipboard. With that, you can have flexibility to do several things, and save some time. For example, with the clipboard, you do make the RTF in DEVONthink with command-N, which is the command to make a new document from the clipboard. Or, you can go directly to Curio and use Edit > Paste As… and get a Plain Text, List, Mind Map, or Table figure. Or paste the list into Excel or Numbers, and so on.
Mod 3: I’ve adjusted this so that the listing will optionally be all the groups in a database, or the children of the currently-selected group
-- 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
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
set the clipboard to my createListing(children of root of theDatabase, "")
else if listScope is "Selected Group and Children" then
set rootGroup to the current group
set the clipboard to my createListing(children of rootGroup, "")
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 this_listing to ""
repeat with this_record in theseRecords
set this_name to (name of this_record as string)
set this_type to type of this_record
if this_type is group then
set this_listing to this_listing & theTabs & this_name & return
step progress indicator this_name
set this_listing to this_listing & my createListing(children of this_record, theTabs & (ASCII character 9))
end if
end repeat
end tell
return this_listing
end createListing
I’ve modified my “clipboard” version of the script (above) to give you an option to either put a listing of the groups in the whole database on the clipboard, or to list just the children of the currently selected group.
I need a list of all groups and subgroups in a database to integrate DevonThink with typinator. I changed the bundle ID and ran the script. There were no errors. I stopped after 5 minutes because with Evernote a similar script take a minute.
Should I just be patient or does this script not apply to to DevonThink Pro 3 ?
thank you @korm
thank you @pete31. I discovered it after this post and am trying it (still running) . The problem is that it seems to be listing everything including documents. All I want are groups and subgroups
thank you
This modified script copies the structure for the group you’ve selected in the sidebar or for the whole database.
Remove the tabs afterwards (in e.g. BBEdit) to get a plain names listing.
-- Copy group names (structure)
-- 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
tell application id "DNtp"
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 SubGroups", "Cancel"} default button 1 cancel button 3 with title "Put a Group Listing on the Clipboard")
if listScope is "Whole Database" then
set the clipboard to my createListing(children of root of theDatabase, "")
else if listScope is "Selected Group and SubGroups" then
set rootGroup to the current group
set the clipboard to my createListing(children of rootGroup, "")
else
return
end if
hide progress indicator
display notification "Listing in clipboard!" with title "Create Listing"
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 "DNtp"
set this_listing to ""
repeat with this_record in theseRecords
set this_name to (name of this_record as string)
set this_type to (type of this_record) as string
if this_type is "group" or this_type is "«constant DtypDTgr»" then
set this_listing to this_listing & theTabs & this_name & return
step progress indicator this_name
set this_listing to this_listing & my createListing(children of this_record, theTabs & (ASCII character 9))
end if
end repeat
end tell
return this_listing
end createListing
I am running the script which takes time (no problem). Not finished yet which is why I did not reply immediately. I will obviously give you a follow up. I greatly appreciate your help