BBEdit Scripts

pudge on 2005-03-31T23:13:49

John Gruber has a new version of a script to open lots of files in one window in BBEdit. The only one was harder, because there was nothing in the AppleScript dictionary for it, and the command line program couldn't do it.

I wrote a version in Perl, and the new version is quite a bit shorter:

#!/usr/bin/perl
use Mac::Glue ':all';
my $bbedit = new Mac::Glue 'BBEdit';
$bbedit->obj(file => \@ARGV)->open(opening_in => enum('new_window'));


Although for command-line purposes, I'll use this Perl script, called bbeditm:

#!/usr/bin/perl
system 'bbedit', '--new-window', @ARGV;


I have some other similar scripts for BBEdit. One is for using as my default $EDITOR. You see, normally, bbedit(1) will open your files and return immediately. It has an option to wait, but if you set EDITOR='bbedit -w', some programs won't use it because $EDITOR is not executable. So, make an executable, called bbeditw:

#!/usr/bin/perl
system 'bbedit', '-w', '--resume', '-c', @ARGV;


Something else I do a lot is pipe program output to BBEdit. To make this easier, bbedit(1) provides options to scroll up to the top of the window, instead of starting at the bottom, and another option to make it so I can close the window without telling it to not save, and I wrote bbeditd:

#!/usr/bin/perl
system 'bbedit', '--view-top', '--clean', '-t', 'Program Output', @ARGV;


Much of the time I use this in the form of perldoc -t Mac::Glue | bbeditd or gluedoc -t BBEdit | bbeditd, so I shortened that, too, in bbeditp:

#!/usr/bin/perl -s
our $g;
my $prog = $g ? 'gluedoc' : 'perldoc';
my $doc = shift;
open STDOUT, "|bbedit --view-top --clean -t $doc";
system $prog, '-t', $doc;