Open DEVONthink group via Launchbar

Hi,

I just created an short AppleScript which is meant to be used via LaunchBar. It allows searching for groups in all open DEVONthink databases whose name contains the searchtext. When only one group is found, it is opened; when multiple groups the results are displayed directly in LaunchBar by passing a script generated XML.

Sven.


# Search DEVONthink Group.scpt
#
#
# Script Action for LaunchBar
#
# searches open DEVONthink databases for groups whose name contains searchtext
# when only one group is found, it is opened; when multiple groups are found
# it displays the results directly in LaunchBar by passing a script generated XML
# to LaunchBar. 
#
# 2013-10-17: first version
#
# includes code from the "SafariTabsActions" Scripts provided by objective delevopment
#
# http://blog.obdev.at/post/launchbar-action-to-list-safari-tabs/
# http://www.obdev.at/ftp/blog/SafariTabsActions.zip


on encodeTitle(theTitle)
	set theTitle to my replaceChars(theTitle, "&", "&")
	set theTitle to my replaceChars(theTitle, "<", "&lt;")
	set theTitle to my replaceChars(theTitle, ">", "&gt;")
	return theTitle
end encodeTitle

on replaceChars(theText, searchString, replacementString)
	set AppleScript's text item delimiters to the searchString
	set the item_list to every text item of theText
	set AppleScript's text item delimiters to the replacementString
	set theText to the item_list as string
	set AppleScript's text item delimiters to ""
	return theText
end replaceChars

on search_devonthink_for_group(my_search_text)
	
	tell application id "com.devon-technologies.thinkpro2"
		
		set my_group_list to {}
		set list_of_databases to get every database
		
		repeat with my_database in list_of_databases
			
			set my_list to (search "*" & my_search_text & "*" in root of my_database within titles)
			
			repeat with my_item in my_list
				if type of my_item = group then
					set end of my_group_list to my_item
				end if
			end repeat
		end repeat
		
		if (count of my_group_list) > 1 then
			
			set the_XML to "<?xml version='1.0'?><items>"
			
			repeat with my_group in my_group_list
				set my_url to reference URL of my_group
				set my_title to my encodeTitle(name of my_group)
				set my_subtitle to name of database of my_group & location of my_group
				set the_XML to the_XML & ("<item>" & "<title>" & my_title & "</title><subtitle>" & my_subtitle & "</subtitle><url>" & my_url & "</url></item>")
				
			end repeat
			
			set the_XML to the_XML & "</items>"
			
			tell application "LaunchBar" to set selection as list to the_XML
			
		else
			activate
			open window for record item 1 of my_group_list
		end if
	end tell
	
end search_devonthink_for_group

on handle_string(my_search_text)
	search_devonthink_for_group(my_search_text)
end handle_string

on run
	activate me
	set my_search_text to text returned of (display dialog "Search text?" default answer "")
	search_devonthink_for_group(my_search_text)
end run

Hello Sven,

Thanks for this! I got it to work well.

Saved the script in the DTPro scripts folder -

Have this folder indexed by Launchbar

Updated the LB index

And it worked well!

Thanks from here too! This is very useful for quick access. I have a folder with bookmarks for groups, that I very frequently use, indexed by LaunchBar. Many of them I want to access in no time while talking with customers, but I cannot cover every case with a bookmark. Your script is a first class premium addition for my situation.

A nice side benefit is that hitting the ‘space’ key on a found group reveals it’s DEVONthink item-link.

Thanks for sharing your script. I installed it as well and it fills an important navigation need for me.

I am surprised that DevonThink still does not have an option for keyboard navigation to a group (or a tag). Hopefully it is on their list of features to add.

+1

Such as…
I don’t know what this is supposed to look / feel like.

This is what I had used extensively in Evernote. Screenshot attached.
Very fast and quick jump to the desired note, notebook or tag.

All without using the mouse…
Screen Shot 2016-10-11 at 11.10.10 AM.jpg