Scripts: Search in new window

After reading this thread DT3beta: No dedicated search-window? I thought these little scripts might be useful.

They all open a new window so you don’t loose your context in your current window.

This one sets the focus to the search field, ready to type:

-- New window and focus search field

activate application id "DNtp"
tell application "System Events"
	tell process "DEVONthink 3"
		keystroke "n" using {option down, command down}
		delay 0.2
		repeat with i from 1 to 10
			try
				set focused of text field 1 of group i of toolbar 1 of window 1 to true
				exit repeat
			end try
		end repeat
	end tell
end tell

This one sets the search field to the given text, e.g. a search prefix you use often and don’t want to type over and over again:

-- Set search field to text

activate application id "DNtp"
tell application "System Events"
	tell process "DEVONthink 3"
		keystroke "n" using {option down, command down}
		delay 0.2
		repeat with i from 1 to 10
			try
				set focused of text field 1 of group i of toolbar 1 of window 1 to true
				set value of text field 1 of group i of toolbar 1 of window 1 to "name:"
				--key code 36
				exit repeat
			end try
		end repeat
	end tell
end tell

The one above can also be used to directly start the search, just uncomment key code 36 (but if you don’t want to interact with the search field I think using search query from the dictionary makes more sense.)

The last one deletes the search field:

-- Delete search field

activate application id "DNtp"
tell application "System Events"
	tell process "DEVONthink 3"
		repeat with i from 1 to 10
			try
				set focused of text field 1 of group i of toolbar 1 of window 1 to true
				set value of text field 1 of group i of toolbar 1 of window 1 to ""
				exit repeat
			end try
		end repeat
	end tell
end tell

If they at some point don’t work reliably try adjusting the delay. I don’t know the maximum of toolbar groups in DEVONthink 3, so if setting the delay doesn’t work try to set the repeat times higher.

Hope it’s useful

1 Like

Or…

:wink:

:wink:

Thanks as always Pete :slight_smile: The second one is something I was looking for.

(؛ ˙ƃuıɥʇǝɯos noʎ puǝs oʇ pǝǝu ı 'ǝʇǝd ǝןıɟoɹd ɹnoʎ ǝpıɥun

1 Like

HI Pete, with BETA3 now these scripts aren’t working for me, I wonder what happened.

Tried them in Beta 3 and all of them work over here

Strange! After updating to Beta3 these aren’t working.
For one of the scripts, It brings up the window but the cursor(focus) doesn’t go to the search field and for the other it doesn’t execute the word I have input.

activate application id “DNtp”
tell application “System Events”
tell process “DEVONthink 3”
repeat with i from 1 to 10
try
set focused of text field 1 of group i of toolbar 1 of window 1 to true
set value of text field 1 of group i of toolbar 1 of window 1 to “”
exit repeat
end try
end repeat
end tell
end tell


activate application id “DNtp”
tell application “System Events”
tell process “DEVONthink 3”
keystroke “n” using {option down, command down}
delay 0.2
repeat with i from 1 to 10
try
set focused of text field 1 of group i of toolbar 1 of window 1 to true
set value of text field 1 of group i of toolbar 1 of window 1 to “choose”
–key code 36
exit repeat
end try
end repeat
end tell
end tell

You have curly quotes. Paste the code you posted in Script Editor and try to compile it. It won’t. Replace them with straight quotes (or copy the scripts from my first post) and it should work. I’ve got no idea how Beta 3 could have changed the quotes and believe that it doesn’t. However if you change scripts in the script menu restart DEVONthink 3 afterwards.

Thanks Pete but still not working.
I copied from your posts and pasted it in Scrip editor and still it doesn’t work
I even changed the delay to higher than 0.2 but still not working.

The scrip runs and It does bring up a new window but that’s it.

Here is how it looks.

Set the repeat to 20 or even higher. I don‘t know how many UI groups the toolbar can have. If you use a large screen and added many toolbar items 10 repeats may not be enough (see my first post)z

Thanks. I changed it to 20, 40, 80 but still it doesn’t work. No I don’t have a large screen.

Something Beta3 did, I can’t figure it out. Other users are reporting some scripts aren’t working for them too, after Beta3.

Thanks anyway Pete.

As the script uses user interface scripting, a minor revision of the user interface or a different setup of the window might already break it.

1 Like

Set the repeat to 20 or even higher. I don‘t know how many UI groups the toolbar can have.

Again, another reason why UI scripting is fragile and should not be depended on, except in unusual circumstances.

BTW:
Since version 3 there’s a new “search query” property of viewer windows, setting it performs a search:

tell application id "DNtp"
	set search query of viewer window 1 to "Test"
end tell
2 Likes

Is there a change log of DEVONthink’s AppleScript dictionary? Would be very much appreciated

What changes are made in the app are generally in the Release Notes, but there’s nothing beyond that.