Skip to content

Instantly share code, notes, and snippets.

@bclennox
Created September 13, 2011 18:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bclennox/1214623 to your computer and use it in GitHub Desktop.
BBEdit Menu Script to act like TextMate's commenter
on menuselect(menuName, itemName)
tell application "BBEdit"
if (length of (selection of text window 1) > 0) then
return false
else
set documentMode to source language of text document 1
if (documentMode is "Ruby" or documentMode is "Unix Shell Script") then
set commentDelimiter to "# "
else
set commentDelimiter to "// "
end if
set theLineNumber to ((startLine of selection) of text window 1)
set theLineReference to (line theLineNumber of text document 1)
set theLine to (contents of theLineReference) as string
if (theLine begins with commentDelimiter) then
delete (characters 1 thru (length of commentDelimiter)) of theLineReference
else
select insertion point before (character 1 of theLineReference)
set selection to commentDelimiter
select insertion point before (character 1 of theLineReference)
end if
return true
end if
end tell
end menuselect
@bclennox
Copy link
Author

Note: You must use Finder to name this file "Text•Un/Comment Selection.scpt" and save it in your BBEdit Menu Scripts folder. Terminal and Script Editor do not allow slashes in filenames. See my article for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment