I was searching for a way to rename the current BBEdit document today when 
I ran across a 14-year-old AppleScript from John Gruber: 
<https://daringfireball.net/2004/10/rename_active_document>

Here's the script for the then-current BBEdit-8

tell application "BBEdit"
activate
set old_name to name of text window 1
set dialog_result to display dialog ¬
"Rename active document:" default answer (old_name) ¬
buttons {"Cancel", "Rename"} default button 2 ¬
with icon note
if button returned of dialog_result = "Rename" then
set new_name to text returned of dialog_result
set d to active document of text window 1
if (d's on disk) then
set the_file to d's file
tell application "Finder"
set name of the_file to new_name
end tell
else -- it's a document that has never been saved
set name of d to new_name
end if
end if
end tell

This _almost_ works for me, but I can't figure out what's wrong, and I 
don't know enough about AppleScript to fix it.

When I tried it, I was prompted with the current filename (but without the 
file's extension, not that I really cared about the file extension in this 
case, but it seems like it should be included in case I _did_ want to 
change it).

However, when I tried to rename the file, I received this error:

Finder got an error: Can’t set name of file 
"SSD:Users:luomat:Dropbox:scripts:pdf-remove-ATLA-last-page.sh" to 
"atla-remove-last-pdf-page.sh".

If I had to guess, I'd say that I need to tell the Finder to use the full 
path (aka 'dirname' in Unix parlance) of 'the_file' for 'new_name'.

But I'm not sure how to do that (neither am I 100% sure that is the 
problem, I'm just guessing from the error message).

Anyone already have this solved, or able to suggest a solution?

Bonus points if you can change the extension too, but if I can rename the 
current file with the current file extension I will still be better off 
than I am right now!

Thanks!

TjL


-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to