On Jul 26, 2007, at 7:28 AM, Doug McNutt wrote:
But what I would really like is to have the ENTER key execute shell
commands, the way it does in MPW, for all BBEdit windows.
Here's a simple AppleScript I wrote some time ago that executes the
current selection (or current line if nothing is selected). If the
document's source language is set to PHP/HTML, Ruby, or Perl, the
AppleScript will use the appropriate interpreter to execute the
command. Otherwise, all commands are executed in the shell.
tell application "BBEdit"
tell text window 1
set lineNumber to startLine of selection
set lineLength to length of line lineNumber
if lineLength is 0 then
beep
return
else if length of selection is 0 then
set theCommand to¬
(characters 1 through lineLength of line lineNumber)¬
as text
else
set theCommand to selection as text
end if
set originalContent to¬
(characters 1 through lineLength of line lineNumber)¬
as text
set fileType to source language of text document 1
if fileType is "PHP" or fileType is "HTML" then
set theCommand to "php -r '" & theCommand & "'"
else if fileType is "Perl" then
set theCommand to "perl -e '" & theCommand & "'"
else if fileType is "Ruby" then
set theCommand to "ruby -e '" & theCommand & "'"
end if
try
set theResult to do shell script theCommand
on error the errorMsg number the errorNum
beep
display dialog "Error: " & the errorNum & ". " &¬
the errorMsg with icon stop buttons {"Cancel"}¬
default button 1
end try
set line lineNumber to originalContent & return &¬
theResult
select insertion point after line lineNumber
end tell
end tell
Hope this helps,
Dennis
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>