Skip to content

Instantly share code, notes, and snippets.

@benspaulding
Created October 16, 2011 04:33
Show Gist options
  • Select an option

  • Save benspaulding/1290510 to your computer and use it in GitHub Desktop.

Select an option

Save benspaulding/1290510 to your computer and use it in GitHub Desktop.
Intelligently rename active document in BBEdit.
(*
File:
Rename Active Document.scpt
Abstract:
This script will intelligently rename the active document in BBEdit.
Version:
1.1
Author:
John Gruber <http://daringfireball.net/>
Modified By:
Ben Spaulding <http://benspaulding.us/>
Details:
For more information, see the following:
- http://daringfireball.net/2004/10/rename_active_document
- BBEdit User Manual
*)
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"
-- I was getting an error from Finder, and the following alias
-- fixed it. I wish I fully understood why.
set the_file to the_file as alias
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment