Reading a List of Files from a DEVONthink Group

Hello guys...
and girls?

I have a KM macro that looks into a folder on my computer, reads the file names and adds them to an excel file.
I read the files with the below action.

I recently moved my files into Devonthink and I like it so far.
I'd like to move this folder in Devonthink as well but then my script won't work.

Does anybody know how to do the action above but looking into a Devonthink group instead?

Thanks in advance!

Panos

Hi guys,

Does anyone have any idea on how to do this?

This AppleScript gets the base names separated by a new line.

Save the script result to a variable.

-- DEVONthink - Get base names of group children

property theUUID : "490FC346-E462-4ABD-8FEC-F15DEE7CF288" -- Set the UUID of your Group or Smart Group here

tell application id "DNtp"
	try
		set theGroup to (get record with uuid theUUID)
		set theChildren to children of theGroup
		
		set theChildrenNames to {}
		
		repeat with thisChild in theChildren
			set thisName to name of thisChild as string
			set thisFilename to filename of thisChild as string
			if thisName = thisFilename then set thisName to my recordName(thisName, thisFilename)
			set end of theChildrenNames to thisName
		end repeat
		
		set theChildrenNames_string to my tid(theChildrenNames, linefeed)
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

on recordName(theName, theFilename)
	set theSuffix to my getSuffix(theFilename)
	if theName ends with theSuffix and theName ≠ theSuffix then set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
	return theName
end recordName

on getSuffix(thePath)
	set revPath to reverse of characters in thePath as string
	set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
end getSuffix

on tid(theList, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theString to theList as text
	set AppleScript's text item delimiters to d
	return theString
end tid

1 Like

Thank you pete31!

I'll try it.

@pete31 I tested your script and it's working great!!

Can I ask if there is a way to only pick up some files and not all?
Let me explain.
Currently, I have my receipts scanned into different folders, per month, so if they are in Finder it's easy to determine the date in KM and check the correct folder.
However if I move them to DevonThink, and use your script, they will all have to be in the same folder.
But my receipts are all named like "2020-10-30 - meal receipt.pdf" so if I could have the script only pick up the ones for a specific month that would be amazing.

Would that be possible?

Thanks

Set theUUID to the uuid of a Smart Group :slight_smile:

That's brilliant. I didn't think about that at all!

Thanks again for your help!!

1 Like