You don’t need a script for that 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
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
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.
~/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.
Yep thanks Jim. Apparently it isn’t supported anymore
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)
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.
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 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.