Scripting Help for the Hopeless (from Launchbar)

Hey, y’all, I’m trying to put together a simple script so that I can search Devonthink from Launchbar. For those who don’t use Launchbar, you can input a text string and use “on handle_string” to pass it to a script. I’m hopeless with AppleScript (and won’t be too offended if you tell me to RTFM), but if you have a minute, can you tell me how the “search” command in a script. Is this even the correct command to use. I’ve looked in the dictionary, but I’m not sure how I should be inputing things. Here’s what I have so far (I know it’s a pathetic skeleton, but …). Thanks in advance for any help.

on handle_string(theName)
–the above line grabs the text from launchbar
try
tell application “DEVONthink Pro”
search theName in “/”
end tell
on error error_message
display dialog error_message
end try
end handle_string

The syntax is…


search theName comparison no case within all operator all words

This example searches case insensitive in both contents and title, URL/path and comments using the AND operator (All words).

Christian,

Thanks for the info. Of course, it’s still not making my script work :wink:, but that’s OK. I obviously don’t know what I’m doing when it comes to AppleScript ( … it seems so easy, and yet … ). If you have the time (and I mean, if it won’t take you any longer than the time to type it, which is all it might take) can you figure out what this script should look like. My idea is that using Launchbar, I can bring up the script, hit space to open the text input box, put in a search term(s), hit return, and have DTPro pop up with the search completed and the results showing. I guess I’m almost looking for a Spotlight substitute! It seems like it should work, if I knew anything about AppleScripting, that is. Thanks.

Doug

Doug,

the search command returns the results for further scripting but doesn’t open a search window.

I just tried with no luck. So, Christian, is there any way to bring up search window with the search result?


tell application "DEVONthink Pro"
	set theName to "human rights"
	set theResult to search theName comparison no case within all operator all words in current database
	open search window with theResult
end tell

You could use GUI scripting for example:


-- Using the clipboard if not defined
property pSearchString : "Test"

tell application "DEVONthink Pro"
	activate
	tell application "System Events"
		keystroke "f" using {command down, shift down}
		if pSearchString is "" then
			keystroke "v" using {command down}
		else
			keystroke pSearchString
		end if
		keystroke return
	end tell
end tell

Ah, didn’t think of GUI scripting. Thank you, Christian. That works. Hope next release of DTP is scriptable for this matter. I think this works for dougray, too.

The following script is for Quicksilver. You need to save this applescript as script to ~/Library/Application Support/Quicksilver/Actions. It wouldn’t work unless Preferences/extras/Run tasks in background is checked. Restart QS make this applescript recognized. I’ve tested it in QS b49 (3763).

After that, bring up QS, then:

1st pane: enter search string
2nd pane: the name of the script

will get you right to the search result window.


using terms from application "Quicksilver"
	on process text pSearchString		
		tell application "DEVONthink Pro"
			activate
			tell application "System Events"
				keystroke "f" using {command down, shift down}
				if pSearchString is "" then
					keystroke "v" using {command down}
				else
					keystroke pSearchString
				end if
				keystroke return
			end tell
		end tell
	end process text
end using terms from

This is a rough guess, but there is a user report that GUI scripting (not just this one) wouldn’t work with QS hot key trigger because the trigger key combo gets into the script when pressed, so don’t be surprised if your hot key trigger for this script fails. It works okay as QS action.

You can make it work for LaunchBar with a little modification. If you want to search in a specific database, you can insert open database command right after activate.

Hey, ilovya, thanks for bringing this thread back from the dead! The solution that you and Christian figured out works great in Launchbar with a bit of modification:


on handle_string(pSearchString)
	tell application "DEVONthink Pro"
		activate
		tell application "System Events"
			keystroke "f" using {command down, shift down}
			if pSearchString is "" then
				keystroke "v" using {command down}
			else
				keystroke pSearchString
			end if
			keystroke return
			keystroke return
		end tell
	end tell
end handle_string

The odd thing is that I needed to add 2 returns at the end; 1 return wasn’t registering, but 2 works and brings up the results. As you said, I’d love to see a more “elegant” solution to this, one that doesn’t rely on GUI scripting, but it works all same. Thanks again to you and Christian.

Doug

Glad it is working for you, all thanks to Christian. Hope this will benefit LaunchBar and Quicksilver users.

This is a nice work around, but it seems like it should be more efficient to use the “search” AS term from Devonthink Pro. After all, it does return a list of records. I’ve played with it a little while now. The problem is that I can not create a window with the results listed. I tried


set viewer window selection to (search thisClipping)

But as you would guess, this does not work. Is there a way to create a new window containing a list of records. I could think of other ways this might be useful. Thanks alot.

Gabe

No. The only workaround is to replicate results to a new group (see the smart group scripts for example) and to open this group afterwards.