View DTPO Spotlight metadata for imported files

DTPO gives you the option of building Spotlight-visible metadata for its databases. It’s stored in:

“/Users/…/Library/Caches/Metadata/DEVONthink Pro 2/” by the UUID of the database, and then by the uuid of the database record, plus a “.dtp2” extension (approximately).

It’s some work keeping all those 31-character file and folder names in your head, so the following script will retrieve the Spotlight metadata for a file selected in the database:


tell application "DEVONthink Pro"
	set metadataUUID to uuid of (selection as reference) & ".dtp2"
	set databaseUUID to uuid of database of item 1 of (selection as reference)
end tell

set spotlightData to ""

tell application "Finder"
	set fullPath to a reference to (home as string) & "Library:Caches:Metadata:DEVONthink Pro 2:" & databaseUUID
	set metadataFolders to folders of folder fullPath
	repeat with i in metadataFolders
		set metadataFiles to files of i
		repeat with j in metadataFiles
			set filePath to (name of j)
			if metadataUUID = filePath then
				set filePath to POSIX path of (i as string) & filePath
				set spotlightData to do shell script "mdls " & "\"" & filePath & "\""
			end if
		end repeat
	end repeat
end tell

set result to spotlightData

Caveats: I’m using this with Keyboard Maestro, which has a nice text window to display the results. You’ll have to fiddle to get it to create a text record in DTPO, or whatever you might need, if you don’t have a similar setup.

Works for a selection of one item, no error checking if you do otherwise. :frowning:

Only briefly tested (works for me!). And as usual, back up your precious data, and don’t throw blames if you go down in flame. :wink:

Enjoy, Charles

Just curious but why don’t you access the AppleScript properties (e.g. name, aliases, URL, comment etc.) directly from the selected record instead of retrieving some from a Spotlight metadata cache file?

Hi Christian-

I’ve gotten interested in Spotlight searches courtesy of Leap, which accepts raw search queries, and can display results further classified by folder location.

Prior to this, I felt the “sugar” layered on top of Spotlight’s keywords was just confusing, and the display of returned values not very useful.

So the above Applescript was just an intellectual curiosity on my part, I wouldn’t actually script based on such things. Although I might construct Spotlight queries based on the knowledge.

(It >would< be useful to have a roadmap that relates, say, the radio buttons on the DTPO search window to actual elements/attributes in a record, but as I’m probably the only person that would enjoy such a thing, I’ll make one myself someday…)

Best, Charles