Simple Renaming Dialog Mimicking PathFinder

Edit: See my post downstream in the thread for the reason for this script. The point is to have a larger dialog box to work with than the tiny work area that pressing return provides.

I’m reposting this. Tested several methods of using this script and can find no problems with it. There’s a complaint posted below that it doesn’t work. I cannot account for that, it works here. :confused:

tell application id "DNtp"
	set theRecord to content record
	set theName to the name of theRecord
	set newName to text returned of (display dialog "" default answer theName with title "Edit Name")
	if newName is not equal to "" then
		if newName is not equal to theName then
			set the name of theRecord to newName
		end if
	end if
end tell

Sounds interesting, but I can’t get it to work in Keyboard Maestro. Here’s what I have set up:

DTPO rename popup 2.jpg

(I changed the first line, just in case that was the problem - it didn’t work with the original first line, either).

I assume I’m doing something wrong that is very basic, but have no idea what that might be.

Thanks for the reply. How do I compile a script from within Keyboard Maestro? I also tried calling it from an external file that I compiled in the AppleScript editor, but that didn’t work either. I’m using the latest version of KM.

Hate to ask the obvious, but is the KBM engine running. A lot of time I find that is the “problem” when a script doesn’t work

Yep, the engine is running, as I have other KM items that work, such as automatically closing my databases and unmounting sparse bundles when closing DTPO . I’m sure the script is fine, and that it is something on my end that I’ll end up being embarrassed about. I just can’t figure out what it is (and why I can’t the script to compile from within Keyboard Maestro).

The text in the script in your screen shot is not colorized therefore not compiled – user variables should appear in green, DEVONthink properties in red, AppleScript syntax in black. The button that reads “enable” should read “try”. See the screen shot. Scripts in KM are compiled automatically when the “Edit” button at the bottom of the KM macro window is clicked to stop editing. Since this is not their forum, perhaps the KM manual, or a note to Stairways might answer why. Or, maybe just reboot and try again?

I now have it working! I’m not sure if it’s the reason, but originally I had copied and pasted your code directly from my browser into Keyboard Maestro. I started wondering if there was some hidden formatting that was messing things up, so I first copied it to a plain text editor, and then from there into Keyboard Maestro, and now it works. It could have been something else, but whatever the reason, it works now.

Thanks for this script, and your help. This will be very handy to use.

Hello Korm thanks for the script. I got it to work here…

…but can’t you just hit return and rename any file or group?

Thanks,

The rationale was originally posted and then got erased. The point is to have a larger dialog box to work with than the tiny work area that pressing return provides.

It is the difference between this

and this

Which can make a small difference in DEVONthink’s usability for someone with poor vision and/or difficulty typing. I borrowed the idea from Path Finder, and use the same keyboard shortcut as PF uses: command-shift-R. DEVONthink’s UI gets low points in accessibility – so every little bit helps.

Hey, thank you! This is great, PathFinder user here and out of habit I constantly find my typing cmd + shift + R in DEVONthink Pro Office. “Thunk!”
Now that I put your script to DEVONthink’s script menu and assigned the same shortcut, this finally works. It’s magic. :smiley:

Oh yes you are right. I didn’t see that explanation in the thread so I was curious.

Thanks for pointing it out and also a pathfinder user here - it’s in my top 5 essential apps along with Textexpander and keyboard maestro - launchbar and trickster topping it off with a free clipboard manager called clipmenu (guess that makes 6)- even though launchbar and keyboard maestro have clipboard managers I prefer this little free menu bar item “clipmenu”

Anyway, it’s getting desultory here - i’ll sign off

korm, should you ever modify the script, so that it also works on groups, please post that version here too. I would love it.

Funny you should ask. Here it is. I also added error checking. This only works on a single item at a time (and will error out if more than one is selected – that check can easily be removed from the logic, see the comment in the code).

(* 
v1 original; worked with content records and not groups
v2 modified to work with groups; added error handling 20131021
*)

tell application id "DNtp"
	try
		
		if selection is {} then error "Please select an item to rename"
		set numberSelected to count selection
		
		-- comment the following line to eliminate the "select a single item" error
		if numberSelected is greater than 1 then error "Please select a single item to rename"
		
		set theRecord to the first item of (the selection as list)
		set theName to the name of theRecord
		set newName to text returned of (display dialog "" default answer theName with title "Edit Name")
		if newName is not equal to "" then
			if newName is not equal to theName then
				set the name of theRecord to newName
			end if
		end if
	on error errorMessage
		display dialog errorMessage
	end try
end tell

Beautiful, thank you, Sir!