Getting all folders in a database

Is there a quick way to get a list of all folders in a database (in applescript) other than recursively examining every record to determine if its a group or a document? The search method doesnt let you search by filetype :frowning:

Frederiko

This returns the wrong answer, but I think it’s on the right track. “Every child” does not delve into hierarchies, which is what you would need to do recursively to make this work. You can write a reentrant function to do that recursion.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set theDatabase to the current database
	set theRoot to create location "/" in theDatabase
	set theRecords to (every child of theRoot) as list
	set countGroup to 0
	set groupList to ""
	repeat with thisRecord in theRecords
		if the kind of thisRecord is "Group" then
			set countGroup to countGroup + 1
			set groupList to groupList & (the name of thisRecord) & return
		end if
	end repeat
	display dialog (countGroup as string) & return & groupList
end tell
1 Like

This script returns all groups/tags:


tell application id "DNtp"
	set theDatabase to current database
	return parents of theDatabase
end tell

Thanks korm for the code, which will be helpful to me as well and thank you Christian for the solution I needed. I never thought to look there in Script Debugger’s explorer.

Frederiko