On 2013-02-14 at 3:41 PM, [email protected] (LuKreme) wrote:

Is there a way to execute the lines in the worksheet other than select-all, enter?

Not sure if this is quite what you mean, but in my frequent use of BBEdit worksheets, I've evolved this practice:

Put the call to your executable or script, with any parameters, and also any notes or reminders (commented out), at the top of the worksheet, on multiple lines if necessary, followed by a line with only "#-#-#" on it (without the quotes).

Then run an applescript (see below) that combines two steps:

- the first step selects everything from the line AFTER the line with "#-#-#", to the end of the worksheet, and deletes the selection;

- the second step selects everything from the start of the worksheet up to and including the line with "#-#-#".

At that point press Enter (Command-Return on some keyboards), and the executable runs with the provided parameters. If you need to tweak the executable's params before re-running, do so and then call the same applescript again and it will re-select the lines down to the #-#-#, so you may press Enter. BBEdit prints the executable's output starting just below the #-#-# line.

My work involves taking batches of data through a sequence of processing steps. I have to examine the (verbose) output of each step before proceeding to the next, and I have to be able to back up steps and replicate or modify the processing. So each process gets its own worksheet, and I use this applescript as I run the process, check the output, and then clear the sheet and re-run if necessary. Once I'm satisfied, I save that process's worksheet with the last output on it, and move to the next process. I found simply using Undo unworkable to get back to the starting position if I had been poking around in the process test results before deciding to re-run the script. This applescript to clear and re-set for execution lets me keep my mind on the data, rather than on the mechanics of processing the data. Saving the worksheet when I'm done automatically documents the last params and the output of their associated test results.

The applescript goes in the Application Support/BBEdit/Scripts folder, and I assign it a keyboard command, of course. You can use whatever you want for the "#-#-#" token.

Here is the applescript, which I believe is up-to-date with BBEdit's Applescript dictionary (it definitely works for me with latest BBEdit on Mountain Lion):
##
tell application "BBEdit"
    activate
    set mywindow to shell window 1
    set myToken to "#-#-#"
    -- part 1: clear any previous output
    set lineX to 1000000
    set lastLine to the number of lines of text of mywindow
    repeat with i from 1 to lastLine
        set linetext to contents of line i of text of mywindow
        if linetext contains myToken then
            set lineX to i + 1
            exit repeat
        end if
    end repeat
    if lineX < lastLine then
select text from line lineX of text of mywindow to line lastLine of text of mywindow
        set the selection to ""
    end if
    -- part 2: select the executable lines
select text from line 1 of text of mywindow to line lineX of text of mywindow
end tell

Watch out for email line-wrapping, and my apologies if that was mangled with asterisks the way some people's scripts posted here have been -- someone said that's a G-groups thing??

Here's what the top lines of one of my process worksheets look like (using OS X's standard bash shell):

## get_locations.worksheet
Project='Nov2012'
base_dir='/Users/eagle/Documents/Data/SC_CO'
source_file='v-reg-2012-11-01.txt'
precinct_zones_file='precinct_zones.txt'
# pct_targets='smith jones sc_schools'
pct_targets='smith jones sc_schools wats_schools water_vote'
select='all'
# select='szSitusCity=Santa Cruz'
max='200000'

# Assumes: precinct_districts.txt, precinct_targets.txt

perl /Users/eagle/Documents/lib/get_voter_locations "$base_dir" $source_file \
  $Project $select "$pct_targets" "$precinct_zones_file" $max

#-#-#

[Here's where output will go ...]


##  end of worksheet

Might be something useful in that for you.

HTH



Best Regards,

  - Bruce

_bruce__van_allen__santa_cruz_ca_

--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to