Discussion:
BBEdit and external programs
Aaron Hsu
2008-02-26 08:28:12 UTC
Permalink
Hello All,

Does anyone know if it is possible to "pipe" output such as the
contents of a file to another program? What I am doing is that I have
a REPL that reads in code. What I want to be able to do is make
changes to code in BBEdit, and then send it into a running instance of
my environment, so that, for example, I can make changes to the code
and have those changes take effect in the running instance without
having to reload and re-execute everything. Is this possible?

Aaron Hsu
Email/AIM: ***@mac.com
XMPP: ***@xmpp.ws
Web: http://www.sacrideo.us
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Charlie Garrison
2008-02-27 04:43:10 UTC
Permalink
Good afternoon,
Post by Aaron Hsu
Does anyone know if it is possible to "pipe" output such as the
contents of a file to another program? What I am doing is that
I have a REPL that reads in code. What I want to be able to do
is make changes to code in BBEdit, and then send it into a
running instance of my environment, so that, for example, I can
make changes to the code and have those changes take effect in
the running instance without having to reload and re-execute
everything. Is this possible?
What is REPL?

Anyway, I doubt that you can get BBEdit to reload code on behalf
of another program. But it's easy enough to write a script
(Perl, AppleScript, etc) that can tell the other program that
it's time to re-read the code file. I do something similar with
apache/mod_perl. After I make code changes I hit a command key
which triggers a script (within BBEdit) to tell apache to reload.

As for how to have code changes take effect without reloading;
that will depend on the program that is running the code. Does
it support live code changes?


Charlie
--
Charlie Garrison <***@zeta.org.au>
PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-02-27 04:54:14 UTC
Permalink
Post by Charlie Garrison
Good afternoon,
Post by Aaron Hsu
Does anyone know if it is possible to "pipe" output such as the
contents of a file to another program? What I am doing is that I
have a REPL that reads in code. What I want to be able to do is
make changes to code in BBEdit, and then send it into a running
instance of my environment, so that, for example, I can make
changes to the code and have those changes take effect in the
running instance without having to reload and re-execute
everything. Is this possible?
What is REPL?
I guess that I should have explained a bit better what I was aiming
for. REPL stands for “Read Eval Print Loop” and is something like a
command line interface that allows interactive running of programs and
functions. Specifically, this is for a Scheme system.
Post by Charlie Garrison
Anyway, I doubt that you can get BBEdit to reload code on behalf of
another program. But it's easy enough to write a script (Perl,
AppleScript, etc) that can tell the other program that it's time to
re-read the code file. I do something similar with apache/mod_perl.
After I make code changes I hit a command key which triggers a
script (within BBEdit) to tell apache to reload.
Aaah, see, I would need to actually pipe the file or a selection of
the file into the standard input of a currently running instance of
the program.
Post by Charlie Garrison
As for how to have code changes take effect without reloading; that
will depend on the program that is running the code. Does it support
live code changes?
Live code changes come about as the result of re-evaluating code
passed to the environment, in the same way that you would type new
commands into the command line.

Aaron Hsu
Email/AIM: ***@mac.com
XMPP: ***@xmpp.ws
Web: http://www.sacrideo.us
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Charlie Garrison
2008-02-27 05:23:11 UTC
Permalink
Good afternoon,
Post by Aaron Hsu
Post by Charlie Garrison
As for how to have code changes take effect without reloading;
that will depend on the program that is running the code. Does
it support live code changes?
Live code changes come about as the result of re-evaluating
code passed to the environment, in the same way that you would
type new commands into the command line.
If you can do what you want from the command line, then you will
be able to do it from BBEdit. Unfortunately I don't know enough
about Scheme or your environment to suggest how to do it.

But first I'd look at a BBEdit worksheet. And then I'd look at
creating a Unix Filter.


Charlie
--
Charlie Garrison <***@zeta.org.au>
PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-02-27 05:48:13 UTC
Permalink
Post by Aaron Hsu
Post by Charlie Garrison
As for how to have code changes take effect without reloading;
that will depend on the program that is running the code. Does it
support live code changes?
Live code changes come about as the result of re-evaluating code
passed to the environment, in the same way that you would type new
commands into the command line.
If you can do what you want from the command line, then you will be
able to do it from BBEdit. Unfortunately I don't know enough about
Scheme or your environment to suggest how to do it.
But first I'd look at a BBEdit worksheet. And then I'd look at
creating a Unix Filter.
Well, basically, think of it like this. Here is how a typical workflow
of mine goes right now:

1) Start the Scheme Interpreter by invoking it on a command-line:

$ scheme

2) Open BBEdit with a Scheme file that I am editing.
3) I then “set-up” my Scheme environment by selecting all my Scheme
code and dragging it into the Terminal window. This has the effect of
evaluating all the code from this file in that window.
4) I think run a few tests, and when I make a change to the file, say,
modify the definition of a procedure, then I just highlight the
procedure, and then copy and paste it into the terminal window. Doing
this has the effect of re-evaluating that code and I get the procedure
redefined.

My question is: how can I do this without having to do all the copy
and pasting. I'd like to have something like a command where I could
do “Send file to Scheme” or ”Send selection to Scheme.”

Any ideas? Worksheets are nice in that I can do everything from within
my editor, but…I still want a way that I can send my text to the
environment without having to copy and paste between windows. I am
unsure of how Unix Filters would help this case, but I would be
interested in seeing an example.

Thanks for your help,

Aaron Hsu
Email/AIM: ***@mac.com
XMPP: ***@xmpp.ws
Web: http://www.sacrideo.us
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Charlie Garrison
2008-02-27 08:28:52 UTC
Permalink
Good evening,
Post by Aaron Hsu
My question is: how can I do this without having to do all the
copy and pasting. I'd like to have something like a command
where I could do “Send file to Scheme” or ”Send selection
to Scheme.”
Any ideas? Worksheets are nice in that I can do everything from
within my editor, but…I still want a way that I can send my
text to the environment without having to copy and paste
between windows. I am unsure of how Unix Filters would help
this case, but I would be interested in seeing an example.
This is probably beyond my unix expertise without quite a bit of
trial and error. But it sounds like scheme is creating an
interactive session for you, rather than accepting input on
STDIN. If you can 'pipe' your code to scheme, then it should be
pretty easy, but again I don't have the easy answer.

I was suggesting a Unix Filter since it makes it easy to do
something with the current selection in your BBEdit document.
But there are other ways (eg. AppleScript) of getting the
selected text.

Check the scripting dictionary for Terminal, maybe there is a
way to send data to a terminal window. In which case you would
use AppleScript to get selection from BBEdit document/window and
then set/put that data into terminal window.

I don't think I'll be able to help past that. Someone else on
the list may have some suggestions though.


Charlie
--
Charlie Garrison <***@zeta.org.au>
PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Gregory Ramsperger
2008-04-04 15:24:49 UTC
Permalink
Post by Aaron Hsu
Well, basically, think of it like this. Here is how a typical workflow
$ scheme

2) Open BBEdit with a Scheme file that I am editing.
3) I then “set-up” my Scheme environment by selecting all my Scheme
code and dragging it into the Terminal window. This has the effect of
evaluating all the code from this file in that window.
4) I think run a few tests, and when I make a change to the file, say,
modify the definition of a procedure, then I just highlight the
procedure, and then copy and paste it into the terminal window. Doing
this has the effect of re-evaluating that code and I get the procedure
redefined.
My question is: how can I do this without having to do all the copy
and pasting. I'd like to have something like a command where I could
do “Send file to Scheme” or ”Send selection to Scheme.”
Any ideas? Worksheets are nice in that I can do everything from within
my editor, but…I still want a way that I can send my text to the
environment without having to copy and paste between windows. I am
unsure of how Unix Filters would help this case, but I would be
interested in seeing an example.
Thanks for your help,
I think two scripts will solve most of your problems....

Place these in ~/Library/Application Support/BBEdit/Scripts/
You can then run them via the Scripts Palette or set a keyboard command for them.

Script 1:

(* execute the contents of the current BBEdit window in Terminal *)
on run
set scrpt to ""
tell application "BBEdit"
set scrpt to contents of text window 1
end tell
if scrpt is not "" then
tell application "Terminal"
activate
do script scrpt in window 1
end tell
end if
end run



Script 2:

(* execute the contents of the current select in the current BBEdit window in Terminal *)
on run
set scrpt to ""
tell application "BBEdit"
set scrpt to contents of selection of text window 1
end tell
if scrpt is not "" then
tell application "Terminal"
activate
do script scrpt in window 1
end tell
end if
end run



Alternative Script 1 (if you're using iTerm):


(* execute the contents of the current BBEdit window in iTerm *)
on run
set scrpt to ""
tell application "BBEdit"
set scrpt to contents of text window 1
end tell
if scrpt is not "" then
tell application "iTerm"
activate
tell current session of current terminal
write text scrpt
end tell
end tell
end if
end run





You'll notice that I left error checking up to you. These assueme that there is an open window in both BBEdit and Terminal/iTerm. You could check to see if that was true and then bail or open a window it it is missing.


-Gregory
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-04-05 21:45:08 UTC
Permalink
On Fri, 04 Apr 2008 10:24:49 -0500, Gregory Ramsperger
Post by Gregory Ramsperger
I think two scripts will solve most of your problems....
Place these in ~/Library/Application Support/BBEdit/Scripts/
You can then run them via the Scripts Palette or set a keyboard command for them.
Indeed, these are some nice little scripts that do solve the issue of
having to copy and paste from BBEdit to the Terminal. Thanks! I do not use
AppleScript very often, so I do not usually consider them when I think of
solutions that bridge between applications. I guess I should start
learning to use them more effectively.

However, I do have one question regarding the installation of these
scripts. After placing these scripts inside my Scripts folder, they do not
seem to appear in the Scripts menu. Why is that? I assume that I can also
order them in the menu by using the XX) format that I see used by the
other scripts in this folder, is this correct? The scripts do not show up
in the Scripts Palette either.
--
Aaron Hsu <***@sacrideo.us> | Jabber: ***@jabber.org
``Government is the great fiction through which everybody endeavors to
live at the expense of everybody else.'' - Frederic Bastiat
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Doug McNutt
2008-04-05 22:26:00 UTC
Permalink
Post by Aaron Hsu
Indeed, these are some nice little scripts that do solve the issue of
having to copy and paste from BBEdit to the Terminal.
Don't ignore the bbedit worksheet. You can put shell scripts into a worksheet and execute them with a select followed by a poke of the ENTER key, almost like the MPW of old. Actually , I have my mouse programmed to make the right button be the same as a poke on ENTER.

You can also wrap Applescripts with an osascript command that will accept its input from a "here" document

osascript << ENDSCRIPT
tell application xxx
sutff
end tell
ENDSCRIPT

you can also tell application terminal to run your script

osascript << ENDSCRIPT
tell application "Terminal"
do script (possibly something you have saved to a temp file) in window "anameyoucreated"
end tell
ENDSCRIPT
--
--> Life begins at ovulation. Ladies should endeavor to get every young life fertilized. <--
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-04-06 13:50:32 UTC
Permalink
Hey Doug,

Thanks for your message…
Post by Doug McNutt
Don't ignore the bbedit worksheet. You can put shell scripts
into a worksheet and execute them with a select followed by a
poke of the ENTER key, almost like the MPW of old. Actually , I
have my mouse programmed to make the right button be the same
as a poke on ENTER.
I have taken note of the worksheets in BBEdit, and I will likely
use a combination of them and these AppleScripts, if I can
figure out how to get the AppleScripts to display properly. I
like the worksheets a lot, but sometimes they are not very handy
for doing things like interactive debugging and other things
which require a lot of hands-on work. Maybe I just have not used
them enough to get the feel for them, which is very likely.
--
Aaron Hsu <***@sacrideo.us> | Jabber: ***@jabber.org
``Government is the great fiction through which everybody
endeavors to
live at the expense of everybody else.'' - Frederic Bastiat
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Doug McNutt
2008-04-06 17:04:00 UTC
Permalink
I have taken note of the worksheets in BBEdit, and I will likely use a combination of them and these AppleScripts, if I can figure out how to get the AppleScripts to display properly. I like the worksheets a lot, but sometimes they are not very handy for doing things like interactive debugging and other things which require a lot of hands-on work.
I too have problems with interactive stuff. When the ssh daemon asks for a typed-in password you just can't do it.

Back in the old days, with MPW, you could redirect output to "{Active}" which would write debugging output to the bottom of the current window. I still do that here on my workhorse 8500. An almost as good option is to pipe output to the bbedit tool which will open another window to display it where it doesn't mess up previously stored command sequences.

What worksheets really need it to actually be a shell.
--
--> From the U S of A, the only socialist country that refuses to admit it. <--
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Steve Kalkwarf
2008-04-08 13:13:39 UTC
Permalink
Post by Doug McNutt
I too have problems with interactive stuff. When the ssh daemon
asks for a typed-in password you just can't do it.
I hesitate to mention this because I think it's an awful idea, but...

If you get asked for a password, you can type it into the
worksheet, select, then hit Enter (or Command-Return).

This will take those characters, and stuff them into the waiting session.

Don't tell me what a bad idea this is: I already told you. :-)
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-04-08 14:49:09 UTC
Permalink
Hrm . . .
Post by Steve Kalkwarf
Post by Doug McNutt
I too have problems with interactive stuff. When the ssh
daemon asks for a typed-in password you just can't do it.
I hesitate to mention this because I think it's an awful idea, but...
If you get asked for a password, you can type it into the
worksheet, select, then hit Enter (or Command-Return).
This will take those characters, and stuff them into the
waiting session.
Don't tell me what a bad idea this is: I already told you. :-)
This also does not exactly work on some programs. They error out
without a STDIN or some form of that, and so even if I did have
the inclination to do something like this, I couldn't. :-)
--
Aaron Hsu <***@sacrideo.us> | Jabber: ***@jabber.org
``Government is the great fiction through which everybody
endeavors to
live at the expense of everybody else.'' - Frederic Bastiat
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Doug McNutt
2008-04-08 16:41:05 UTC
Permalink
Post by Aaron Hsu
Hrm . . .
Post by Steve Kalkwarf
Post by Doug McNutt
I too have problems with interactive stuff. When the ssh daemon asks for a typed-in password you just can't do it.
I hesitate to mention this because I think it's an awful idea, but...
If you get asked for a password, you can type it into the worksheet, select, then hit Enter (or Command-Return).
This will take those characters, and stuff them into the waiting session.
Don't tell me what a bad idea this is: I already told you. :-)
This also does not exactly work on some programs. They error out without a STDIN or some form of that, and so even if I did have the inclination to do something like this, I couldn't. :-)
try

sudo ls

Hint: To recover, open Terminal:
ps -auxww | grep sudo
sudo kill (the process id from the grep.)

Even putting the mouse over the name of the tool at the bottom of the BBEdit window doesn't work.
--
--> If it's not on fire it's a software problem. <--
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Gregory Ramsperger
2008-04-09 03:38:01 UTC
Permalink
Post by Aaron Hsu
However, I do have one question regarding the installation of these
scripts. After placing these scripts inside my Scripts folder, they do not
seem to appear in the Scripts menu. Why is that? I assume that I can also
order them in the menu by using the XX) format that I see used by the
other scripts in this folder, is this correct? The scripts do not show up
in the Scripts Palette either.
They should jsut show up--but they have to be saved as scripts, not text. Easiest way is to just use Script Editor, paste the text in, compile, and save.

You'll also have to quit and restart BBEdit first.

The XX) works for folders. I've never tried for files. I think it may be in the manual though....

-g
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Aaron Hsu
2008-04-09 04:49:24 UTC
Permalink
Hello Gregory,

Thank you for your advice...
Post by Gregory Ramsperger
They should jsut show up--but they have to be saved as scripts, not
text. Easiest way is to just use Script Editor, paste the text in,
compile, and save.
That was the key. :-) Doing that solved my issue.
--
Aaron Hsu <***@sacrideo.us> | Jabber: ***@jabber.org
``Government is the great fiction through which everybody endeavors to
live at the expense of everybody else.'' - Frederic Bastiat
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, 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: <bbedit-talk-***@barebones.com>
Loading...