(Applescript schmuck) Getting search results from DT3 into LaunchBar

It’s been long enough since I last demeaned myself with my hopelessness with Applescript that I thought it was worth another shot at self-abasement. Here am I!

I miss being able to use a distinct search window in DT3. Rather than see this is a shortcoming, I saw this as an opportunity to tie in one of my other favourite tools, LaunchBar, and make a custom action to start a search from LB that would find matching items in DT3 and present them as a list, with the option to open them directly (or in external tools).

So far, so good.

Then I tried to write some code.

on findMatchingItems(_string)
	tell application id "DNtp"
		set resultList to search _string
	end tell
	-- optional properties:
	-- title, subtitle, label/badge,icon,quickLookURL,action,actionBundleIdentifier 
	set results to {}
	repeat with result in resultList
		set rName to get name of result
		if exists uuid of result then
			set rUUID to uuid of result
		end if
		set rPath to "internal"
		if exists path of result then
			set rUUID to uuid of result
		end if
		set results to results & [{title:rName, subtitle:rSubtitle, path:rPath}]
	end repeat
	return results
end findMatchingItems

set myItemsHere to findMatchingItems("films")

However, I seem to keel over when I try to access the UUID or Path of any results I get back from the search.

Where am I obviously going wrong, DT Applescript power users?

1 Like

Hi, I have zero knowledge about Applescript and perhaps I am misunderstanding your question, but am I understanding correctly that you are unable to search in DT3 using Launchbar? I am asking because I am able to search in DT3 using Launchbar:

Thanks MaSp, I didn’t realise that was an option - however, it just exposes names, rather than hooks into the full search API, which is what I was trying to implement. I still think there’s value to provide full-text search from the LaunchBar interface, usually because I can’t remember my titles but can remember unique text strings within my DEVONthink database!

I don’t know how much more code you have but there is no rSubtitle defined in the code before you try and use it in the results.

Hi Bluefrog!

Yes, this is a slightly cut-down version of what I’m fighting with: my main issue is that when I get a set of results back from the search, I can’t pull out the properties I want from it: the main culprit is getting the ‘uuid’ from the result item, which throws the following error at me:

error "DEVONthink 3 got an error: Can’t make |uuid| of content id 311891 of database id 2 into type reference." number -1700 from |uuid| of content id 311891 of database id 2 to reference

I suspect (for now) all my other problems relate to similar issues! As a complete Applescript hack, I’m not sure how to access this property - or even how to properly debug it (without spending a significant outlay!)

The uuid is a DEVONthink specific value, not a general one.

You ended talking to DEVONthink too quickly. Move end tell to just before return results. Do note, I can’t say how performant this will be.

Dear god. Thanks Bluefrog, that’s all it was. It’s working fine now. I can crack on with this.

I had no idea that Applescript had to hang on to talking to the application to understand the data properly - I think the filthiness of JavaScript got to me.

There’s so many weird little questions about Applescript you just don’t think about asking. That’s a day of hair-loss caused by not understanding that unique feature!

No worries!

The issue is entirely logical when you look at it.
You were asking about DEVONthink-specific properties, so you’d need to continue talking to the application to get it. This is no different then me asking you your name, then turning to a shop owner from down your street and asking him your address! He would also throw an error :slight_smile:

I have a soluion in place for this but I need to package it up neatly. It’s kinda slow but I guess that’s partly because I can’t intercept the results as they’re coming, and have to wait for a completed search set, which refreshes every time a new character is added in LaunchBar. I’ll ask more useful questions when the LaunchBar forums are back and not full of kitchen fittings spam. Also, I need to fix and update my other DEVONthink plugin to save face first. If any LB/DTP experts want to pile in early with ideas, let me know for access to the code and repository!

1 Like