Following running an AppleScript, have chosen item be blue, not gray

I have an AppleScript that I run from the toolbar. Its purpose is to rename an item (such as a PDF file) based upon similar items found by “See Also”. The script opens a dialog box and presents a list of possible names to choose between, along with “cancel” and “OK” buttons. If you click on a choice and click on “OK”, the name of the item is changed to that chosen from the dialog box.

The script works fine, but here’s my question. Before I run the script, the item is highlighted in blue. After I run the script and the item has been renamed, it is now highlighted in gray rather than blue. I would prefer that the item stay blue, since what I usually do next is type “Control-C” to file the item in the proper group, and that requires the item to be highlighted in blue, not gray, I just get the “error doink sound” if I type “Control-C” when the item is gray. I first have to click on the item to make it blue again, and then I can type “Control-C”.

This is how the script ends:

	set name of theRecord to choiceName

end tell

Is there something else I can add to the script after “set name” to highlight theRecord to be blue rather than gray? Thanks!

Sounds like the dialog is stealing the focus from DEVONthink. Try to add the activate command to focus DEVONthink again.

1 Like

@pete31, you’re absolutely right, the script is taking the focus. However, I just tried both “activate” on its own, and then "activate application “DEVONthink 3"”, but neither worked. Thanks anyway!

Then it may be necessary to use UI scripting. Could you post the script?

@pete31 I’ve attached it to this message. I had to zip it to allow it to be attached.

Rename From See Also.scpt.zip (10.4 KB)

Thanks. Your script works fine over here, after choosing from the dialog the focus is back on the item list (i.e. the selected record is highlighted in blue).

I’m still on macOS 10.14.6, so this might explain the difference (but I don’t think so).

How are you running the script? Via DEVONthink’s script menu?

1 Like

I’m on MacOS 12.4. I’m running the script in the toolbar by adding it to Library/Application Scripts/com.devon-technologies.think3/Toolbar . I’ll try via the script menu instead and see if that makes a difference.

I just installed it in the menu folder and ran it from the script menu. I get the same thing - the file is still gray after running the script.

What happens when you replace this line

set theChoice to choose from list chooseFromListItems & {theWidthPlaceholder} with prompt "Rename record to:" default items (item 1 of chooseFromListItems) with title ""

with

tell application "SystemUIServer"
	activate
	set theChoice to choose from list chooseFromListItems & {theWidthPlaceholder} with prompt "Rename record to:" default items (item 1 of chooseFromListItems) with title ""
end tell
		
activate

?

1 Like

That fixed it!!! Thank you so much!

2 Likes

@pete31 I just wanted to thank you again - keeping my fingers on the keyboard has really sped up my workflow. BTW, I now have the script both on the toolbar and in the script menu, and I use the latter to customize keyboard shortcuts (in Apple Preferences) for DT to have an app keyboard shortcut for the script. Works great!

2 Likes

Just one minor note:
Instead of parent 1 I would recommend to use location group as this property is identical to the location shown in the user interface whereas parent 1 might also be a tag but not the shown location.

@cgrunenberg Thanks! I made that change as well and it works fine.