Re: How to Run a line of code in external program

2010-01-13 Thread Bruce Van Allen

On 2010-01-12 at 11:31 AM, chriscorb...@gmail.com (Chris) wrote:


Just curious, are people also using the shell worksheet in BBEdit?


Short answer:

Yes.

Long answer:

Oh, yes.

Here's one of my uses:

I prepare voter data for election campaigns. I run large sets of 
data through a series of processes to make a useful voter file 
for campaign planning and voter contact.


The problem: how to manage a complex and time-consuming data 
processing task, as follows:


Each county has its own format for voter registration data, and 
a county's data structures and database field names may change 
from one election to the next. Voter data churns constantly -- 
people move, die, and change name, party, gender, and so on. 
Jurisdiction boundaries, precinct lines, and even zip code areas 
change, too.


In this environment, each time I set up a voter file, I have to 
start from the beginning, building from raw data about voters, 
streets, districts, past elections, and other information, any 
of which might have changed in content or structure since the 
last time I processed it.


A typical county's voter roll requires 17 processes, which 
cumulatively clean, standardize, and cross-tabulate the data 
into final form. Each process ends with tests, whose results 
must be checked (bio-optically ;-) before the next process may 
begin. Some times it's necessary to back up one or more steps in 
the processing when a problem is found.


Running the complete processing series with no interruptions 
takes five to eight hours (I can do other work during most of 
that time).


Is that enough of a problem statement? Add to it the obvious 
need to keep written track of things both during the processing 
and between processing occasions.


My solution:

For each election, each county gets a data processing directory 
into which I copy a set of BBEdit shell worksheets, one for each 
of the 17 processes, plus a few others.


Each worksheet is named for its process; the content of the 
worksheet is  one or more lines of input arguments, followed by 
a call to the script the does the processing. When the script is 
executed, its output prints out on the worksheet.


For my processes, the output includes progress indicators as 
files are read or written, counts of things found, samplings of 
in-process data, and finally the test results from the process 
and the paths to the data file(s) that the process yielded.


Here's an example of one of these worksheets, down to and 
including the line with #-#-#:


A='Project=OCT2009'
B='base_dir=/Volumes/Campaigns/2009/CO_01'
C='source_file=voter_tabs.txt'
D='criteria=all' # 'criteria=age50'
E='crosstab=gender pty_group age_cohort zip'

perl /Volumes/LIB/make_cross_tab_summaries $A $B $C $D $E
#-#-#

The above worksheet sample uses a format that works with the 
standard bash shell under OS X Snow Leopard. My scripts parse 
standard input as name=value pairs.


Select all lines from A= down to and including the line with 
#-#-#. When you press Enter, the output will print below the 
#-#-# line. I have an Applescript that clears the sheet below 
the #-#-# line and then re-selects the top lines and #-#-# line, 
ready for me to press Enter again to re-run the process.


With its own dedicated shell worksheet, each process and its 
input parameters, progress reports, and outcomes may be 
reviewed, re-run, checked, and annotated for future reference. 
Multiple worksheets may be opened and their processes executed 
simultaneously (assuming non-dependence).


There is only one copy, in a central library, of the actual 
script for each processing step; it may be pointed to by 
multiple shell worksheets each with its own parameters.


During script development, I start using the shell worksheet to 
call the script from the very beginning. Reflecting this, the 
first line output from the scripts I'm describing here simply 
shows that the script initialized and loaded its needed modules:


Tue Jan 12 19:21:29 2010  Initializing... Process 5396 using 
BVA::XDATA 3.90, BVA::XUI 2.9, BVA::XACT 1.11, 
Spreadsheet::WriteExcel 2.25


If a script has a problem, warnings and error messages spill out 
down the worksheet (yes, you can cancel a worksheet process), 
becoming breadcrumbs for the warnings are friends path back to 
functioning code.


Perl, the language I most enjoy working in, provides a strong 
set of debugging, profiling, and testing tools. I can invoke 
these with a few lines kept on the worksheet but normally 
commented out. Again, the results from the profiler or test 
suite print out on the worksheet for study.


There's more to how I do all this, but I think you can see that 
this satisfies the requirements of my problem statement quite well.


Most of what I describe could be done on the command line, 
especially by someone adept at using all the tools of that 
environment to pipe output to files, capture warnings, tweak 
input variables, etc.


But I've come to enjoy how handy it is to 

Re: How to Run a line of code in external program

2010-01-12 Thread Paul Burney
Hi Dennis,

Your Run Shell Command script has been very, very helpful to me. Thank
you so much for posting it!

-Paul Burney
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-12 Thread Lorin Rivers
I use one (it's a template I made) in particular that's a big part of my 
workflow.

It has the following in it:
# Leopard ps change update 2008.01.31
# Don't forget to unlock
apachectl configtest

# die, die, die
apachectl stop

# start
apachectl start

# let stuff finish, die, start
apachectl graceful

# is the right one running?
ps auxww | grep httpd

This is combined with AppleScripts that alter my Apache config file so 
localhost serves the contents of my current project.

-- 
Lorin Rivers
Mosasaur: Killer Technical Marketing http://www.mosasaur.com
mailto:lriv...@mosasaur.com
512/203.3198 (m)


-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-12 Thread Ron Fleckner


On 12/01/2010, at 9:13 PM, Chris wrote:


Lewis emailed me about this thread - I hadn't maintained or kept track
of the ShellService 1.0 build (or source) for some time, but as it's
fairly simple I went ahead and put together a 2.0 version with builds
for Leopard and Snow Leopard.  This is Apache-2.0 licensed open
source, use at your own risk and feel free to let me know about bugs,
use the source, or send me patches or improvements.

It's on the Open Source page at http://urania-consulting.com.  The
LICENSE-README.rtf explains how it works and what its limitations are
- still not quite as fancy as MPW. ;-)

Regards,
Chris


Hello Chris,

This looks great, but the 10.5 version you offered isn't a universal  
binary and so I can't run it on my G4.  I think a simple rebuild with  
the correct flags set in Xcode would be all that's required to allow  
all of us still running dinosaurs to benefit from your good work.


Ron

-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-09 Thread Doug McNutt
At 15:46 -0700 1/8/10, I wrote:
Quoting:

ShellService is a service component - it provides functionality that other 
applications use.In the Services menu (under the application menu), 
ShellService adds an item called Execute Text. This item will be enabled 
whenever you have text selected in applications which support the service. 
When you choose this item, the text will be sent to the command-line shell and 
executed, and the output of the command will be returned to your text 
window.The way that Execute Text works is very similar to (and inspired by) 
the Worksheet window interface of the venerable MPW, Apple's development 
environment on older Mac systems. MPW was the closest thing to a command-line 
many older Macs had, but it has not been updated for MacOS X. Since MacOS X 
has a full UNIX command line, I thought MPW users might enjoy a 
worksheet-style portal to it.ShellService is free. The author welcomes 
feedback.


And there were a couple of links that I was sure were working. But I lied. The 
*.tar.gz file you download turns out to be an error message in HTML after gzip 
expansion. The tar -x  tool just fails quietly.

Christopher Corbell posted the original service in 2002 and declared it 
freeware at the time. All links to it have disappeared. Mr. Corbell seems to 
have published iPiano for the iPhone more or less recently but I'm not up to 
any more googling.

I have made an image of the *.app file that is the service binary as it exists 
on my OS 10.3.9 box and it works with a new user after I create a directory 
Services under $HOME/Library/ if it's not there already.

mkdir  $HOME/Library/Services

The image is at:  ftp://ftp.macnauchtan.com/Software/BBEdit/Services.dmg  86 
KiB

Warning:  I'll have the lady of the house try the service with OS 10.6 but 
BBEdit isn't installed on her machine. The service doesn't require BBEdit but 
it does depend on Next Step's pasteboard concept in which selections are just 
there without an explicit copy operation to a clipboard.

Note to Bare Bones:  The Execute Text service ought to be available wherever 
BBEdit is installed. It is especially useful in TEXT files when the features of 
worksheet, XML, files are needed but the underlying file will be used by other 
applications. How about making it, or your version of it, an option the way the 
bbedit tool is installed?

I want MPW as a real shell for OS neXt !!

-- 

-- The U. S. Census Bureau missed a bet by not counting all of those embryos 
in cold storage. --
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-08 Thread peter boardman
On 7 Jan 2010, at 02:47, Ben wrote:

 Is there a way to create a key-stroke that will take the current line
 (or selection) and dump it into a nominated window.

I have Command-Enter bound to a Unix filter that evaluates STDIN and prints 
both STDIN and the result to STDOUT. You select some text, Command-Enter, and 
the result appears below the original code. Your script has only to evaluate 
STDIN and return something to STDOUT. BBEdit passes only the selection to the 
filter.

Although it would be possible to write an AppleScript to find the current line, 
select it, and pass it on, I haven't bothered to do this. I find it easier to 
select what I want evaluated - it could be part of a line, or 100 lines.

-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-08 Thread Dennis
On Jan 6, 6:47 pm, Ben ben.aus...@gmail.com wrote:
 Is there a way to create a key-stroke that will take the current line
 (or selection) and dump it into a nominated window.

Here's a quick AppleScript I threw together a couple years ago that
runs the current selection (or the current line if there is no
selection) as a shell command. Furthermore, if it recognizes the
current document's source language, it'll run the selection through
the appropriate interpreter (currently only supports PHP, Perl, and
Ruby). The output of the command is then inserted below the original
selection in the document.

This may not be exactly what you're looking for, but it might serve as
a useful starting point. Do whatever you want with it, but use it at
your own risk. :-)

You can download the script here:

http://www.dennisrande.com/downloads/Run%20Shell%20Command.zip

-Dennis
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-08 Thread Doug McNutt
At 12:58 -0800 1/8/10, Dennis wrote:
You can download the script here:

http://www.dennisrande.com/downloads/Run%20Shell%20Command.zip

The Execute Text service I spoke about earlier came from:

http://www.apple.com/downloads/macosx/unix_open_source/shellservice.html

But that link is broken.

The service, that shows up in my Application_Services menu seems to be stored in
$HOME/Library/Services/

Understand that I'm stuck on OS 10.3.9 for other reasons. It's quite possible 
that the service doesn't work any more but I would have trouble without it.  It 
may be that Dennis' offering is a replacement.

-- 
-- Marriage and kilo are troubled words. Turmoil results when centuries-old 
usage is altered in specialized jargon --.
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-08 Thread Doug McNutt
The lady of the house found this:

http://wsidecar.apple.com/cgi-bin/nph-reg3rdpty1.pl/product=01326platform=osxmethod=sa/ShellService.tar.gz

by looking at some wayback pages.

http://web.archive.org/web/20050302141626/http://www.apple.com/downloads/macosx/unix_open_source/shellservice.html

There is a FileSize item on that page which links to the ShellService tar file 
by Christofer Corbell (MacHotShot.com)

Quoting:

ShellService is a service component - it provides functionality that other 
applications use.In the Services menu (under the application menu), 
ShellService adds an item called Execute Text. This item will be enabled 
whenever you have text selected in applications which support the service. When 
you choose this item, the text will be sent to the command-line shell and 
executed, and the output of the command will be returned to your text 
window.The way that Execute Text works is very similar to (and inspired by) the 
Worksheet window interface of the venerable MPW, Apple's development 
environment on older Mac systems. MPW was the closest thing to a command-line 
many older Macs had, but it has not been updated for MacOS X. Since MacOS X has 
a full UNIX command line, I thought MPW users might enjoy a worksheet-style 
portal to it.ShellService is free. The author welcomes feedback.

-- 

-- From the U S of A, the only socialist country that refuses to admit it. --
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-07 Thread Doug McNutt
At 18:47 -0800 1/6/10, Ben wrote:
G'day all,

I routinely use BBEdit for coding SQL etc, and then have to select,
copy, switch to the terminal window and paste to execute the line.

Is there a way to create a key-stroke that will take the current line
(or selection) and dump it into a nominated window.

I'm guessing it might already exist (many other text editors have this
sort of feature) or it means scripting something up?

(As an example, the R built in editor uses Cmd-Enter to run either the
current line or current selection in the R console. It would be great
to be able to use BBEdit for R as well, see next post...)

Execute Text is a service I found somewhere long ago.  Have a look at BBEdit's 
BBEdit menu and see if there is a usable service already provided by Apple.

Ann then you can use BBEdit worksheets but perhaps not if you need to use the 
file as an input source to SQL later. That capability died with BBEdit 5 or so 
when Bare Bones changed the format of worksheets from simple TEXT to XML.

The worksheet method allows retention of shell variables - like PWD - The 
service concept will spawn a new shell that is ignorant of earlier settings. 
Applescript will do the same thing while insisting that you use sh instead of 
$SHELL.

-- 

-- A fair tax is one that you pay but I don't --
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Re: How to Run a line of code in external program

2010-01-07 Thread Ben
G'day Doug,

On Jan 8, 1:04 am, Doug McNutt dougl...@macnauchtan.com wrote:

 At 18:47 -0800 1/6/10, Ben wrote:

 Is there a way to create a key-stroke that will take the current line
 (or selection) and dump it into a nominated window.

 Execute Text is a service I found somewhere long ago.  Have a look at 
 BBEdit's BBEdit menu and see if there is a usable service already provided by 
 Apple.

Not that I can see, but I guess the concept opens up some
possibilities. I found a copy as plain text service, I just need to
work out how to

a) select the whole line if nothing is selected, and
b) get it to send to a destination and paste.


 Ann then you can use BBEdit worksheets but perhaps not if you need to use the 
 file as an input source to SQL later. That capability died with BBEdit 5 or 
 so when Bare Bones changed the format of worksheets from simple TEXT to XML.

 The worksheet method allows retention of shell variables - like PWD - The 
 service concept will spawn a new shell that is ignorant of earlier settings. 
 Applescript will do the same thing while insisting that you use sh instead of 
 $SHELL.

Hmm - interesting, but not quite what I was after - I want to be able
to send commands to (for instance) the R console or the psql
program...

thanks for your input

cheers

Ben
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.