Applescript failing (renaming a record)

Hi all (Jim),

the script below is failing with the following message “DEVONthink got an error: Can’t make selected text of think window 1 into type rich text.”

Any thoughts?

tell application "DEVONthink"
	set the name of the content record of think window 1 to the selected text of think window 1
end tell

well I’ve figured it out.

OCR’ing a pdf generates rich text now - I believe, anyways the following works:

tell application id "DNtp"
	set the name of the selected record of think window 1 to the text content of the selected text of think window 1
end tell

You don’t need a script for that :wink: There’s a handy built in command: Edit > Set Name As.
(Also found in the right-click context menu, or just use Ctrl-Cmd-I.)

That said, look at the “Append Title” script that comes with DEVONthink. I’m still an AppleScript beginner, but I think it’s an issue of different object classes/types. Notice the line:

set theText to selected text of think window 1 as string

Changing the script to overwrite the name with the selected text, instead of appending:

tell application id "DNtp"
	try
		if not (exists think window 1) then error "No window is open."
		if not (exists content record) then error "Please open a document."
		set theText to selected text of think window 1 as string
		if theText is missing value or theText is "" then error "No text is selected."
		set name of content record to theText
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

Or for short, without all the exception handling:

tell application id "DNtp"
	set name of content record to (selected text of think window 1 as string)
end tell
1 Like

thanks troej! - I had for years assigned the F6 and F7 keys to set the name as selection, and (I have another script) to append to the name. But I use FastScripts, and I think something is messing up with its ability to bind keystrokes to scripts :frowning:
I will just use my CustomShortcuts app to do it - bind DT’s Edit > Set Name As (thanks) to F6, and bind an append script to F7 again.

I’m not familiar with FastScripts, so I can’t help you there.

Did you try the script filename method?

(PS: nice that the help now includes styling for dark mode!)

1 Like

got it Troej! - already modifying my most used scripts - thanks for the tip!

1 Like

Troej, where should the scripts reside, and who is detecting the ___Cmd-Alt-F2 (or whatever) suffix? Is it the System?

~/Library/Application Scripts/com.devon-technologies.think/Menu and DEVONthink intercepts it when open. However, setting hotkeys in the filename like this is old tech and may not be supported forever.

1 Like

Yep thanks Jim. Apparently it isn’t supported anymore :slight_smile:
Which makes me think, the only way now to add hotkeys for a script is via something like Keyboard Maestro, right (I am having a hard time getting FastScripts to do it, it did before)

Why not just use are often-mentioned CustomShortcuts app from Houdah Software?

CustomShortcuts works super well for commands that are part of the app, but cannot assign hotkeys to a standalone AS

The script mentioned above would only work in the context of DEVONthink :thinking:

aaarggghhh! - I figured out the issue. FastScripts was looking into a folder called “DEVONthink 3” in the Library\Scripts folder ha ha. I created a new folder there named “DEVONthink”, moved all my own scripts there, and Bob’s your uncle.

1 Like

Now I can play with ALL the cool scripts everybody, including yourself, had created all these years :slight_smile:

Actually, I have three uncles and a cousin named Bob :stuck_out_tongue:

1 Like

So they ARE your uncle!
(I should have said Bob’s your uncles)

1 Like

So, a curiosity about CustomShortcuts.
It requires the commands to be entered in the form

Data * OCR * to searchable PDF

where instead of the asterisks, you have to insert a neat arrow-right, which cannot be found in the Mac keyboard viewer, but of course has some ASCII value. I couldn’t figure out how to type it, and of course when to CustomShortcuts help :wink: and it said just hit the TAB key. Amusing. 55 years using tab keys to enter text tabs, would have NEVER occured to me. But hey, it works.

1 Like