TweetFollow Us on Twitter

BBEdit: Somehow, It Still Doesn't Suck!

Volume Number: 21 (2005)
Issue Number: 2
Column Tag: New Technology

Getting Started

by Dave Mark

BBEdit: Somehow, It Still Doesn't Suck!

A long time ago, in a galaxy far, far away, a guy named Rich Siegel released a nice little piece of freeware named BBEdit. Released back in 1991, BBEdit was designed to edit text files and, as its famous marketing campaign trumpeted, it didn't suck. Over the years, we've seen a ton of software packages come and go, or become bloated with unnecessary features just to keep the update fairy happy. Somehow, BBEdit has kept its trim, unsucky figure, yet still managed to shoehorn in an amazing number of extremely useful features.

I recently upgraded to BBEdit 8, and thought it might be worth spending some time exploring BBEdit - the old, the new, and even an interesting, yet secret, nook and cranny or two. Before we get started, take a minute to download the BBEdit demo, if you don't already have it installed, of course. Here's the URL:

http://www.barebones.com/products/bbedit/demo.shtml

Multi-File Search

BBEdit 1.0 first shipped as freeware back in 1991. One of its most notable features was multi-file search and replace, one of the first applications to offer this. Over the years, BBEdit's multi-file search has evolved into an incredibly powerful tool, one that I find has uses far beyond BBEdit's environment. Here's an example.

Launch BBEdit. If it doesn't automatically create a new, untitled document, create one yourself or open your favorite text file.

Now select Find... from the Search menu. A dialog like the one shown in Figure 1 will appear. Enter some text to search for. In my case, I wanted to find some source code that worked with the IOBluetoothDevice class.

At the bottom of the dialog, I checked the Multi-File Search checkbox. This caused the Sources drawer to open off the left side of the window. There are several ways to populate this window. You can open a Finder window, select a folder that you'd like to search, and drag it into the Sources drawer. Another way is to click on the Other... button in the bottom-right of the window, then choose the folder you'd like added to your search list.

As you can see, you can even add a web site to your search list (love this feature). In addition, BBEdit automatically builds a list of your recent folders.


Figure 1. Multi-file Search.

Once you are happy with your search setup, click the Find All button. BBEdit will launch a thread for each specified directory and will return control to you. Each search is recursive with respect to the directory. Figure 2 shows my search, in progress, as it searches the Developer/Examples directory. BBEdit will recursively search each file in the directory, scanning its contents for the string IOBluetoothDevice.

When I took the screenshot in Figure 2, BBEdit had found 21 occurrences of the string. If I had clicked the Stop button, BBEdit would have presented me with a list of the 21 occurrences it had found so far.


Figure 2. A Search in progress.

Each search builds a list of results that you can work with. Figure 3 shows the results of my search for IOBluetoothDevice. There were 21 occurrences. As you might expect, the search window organizes the search results by file. Click on a result in the upper pane of the search results window and the appropriate file contents are scrolled into view in the bottom pane with the search string highlighted.

Want to edit the file? Click on the result and click the Open button (upper right corner of the search results window) or double-click on the result and the file will open for editing in BBEdit.


Figure 3. Working with the search results.

Opening Remote Files

Ever have to logon to an FTP site, just to edit a single file? Typically, you'll fire up your FTP client, download the file in question, edit the file, save it, then go back to your FTP client and upload the file again. If the file is part of a web site, you might repeat this cycle a number of times till you get things looking just right!

BBEdit offers the ability to open and edit remote files via FTP and SFTP. This means you can open, edit, and save the file, all without leaving BBEdit. And once you've opened the file remotely, you can edit, save, test, edit, save, test, all without leaving BBEdit.

Here's an example. In BBEdit, select Open from FTP/SFTP Server... from the File menu. When the open dialog appears, type in your favorite FTP server info. For anonymous FTP, leave the User Name and Password fields blank.

In my session, I connected to Apple's FTP server using the server name ftp.apple.com and anonymous FTP. To login, I pressed the Connect button. When the list of files at ftp.apple.com appeared, I double-clicked the developer directory, then selected one of the txt files in the directory and clicked the Open button (see Figure 4). The selected document opened in BBEdit. Since this particular FTP site does not give write permission to anonymous FTP, I was not able to save changes I made to the document, but if I did have the right permissions, I could have edited the doc and selected Save to save the changed doc back on the server.


Figure 4. Opening a remote file from Apple's FTP server.

AppleScript

BBEdit is one of the most studly AppleScript apps in existence. To give you a sense of this, Apple uses BBEdit to test new versions of the Apple Event Manager. BBEdit is recordable, meaning you can use tools like the Script Editor to record a sequence of BBEdit events as an AppleScript. BBEdit is scriptable, meaning you can write scripts that make use of BBEdit's object model to access and control any BBEdit objects. Finally, BBEdit is attachable, which means you can add scripts to the application itself.

To truly see this magnificent studliness for yourself, launch Script Editor and select Open Dictionary... from the File menu. When prompted, double-click on the BBEdit entry in the app list (see Figure 5).


Figure 5. Opening BBEdit's AppleScript dictionary.

Ordinarily, I would take the time to step through the dictionary, pointing out specific examples along with some interesting scripts. But the dictionary is so flipping big! And lovely! Open the dictionary in Script Editor and take a look for yourself.

Another way to explore BBEdit's AppleScriptiness is to launch BBEdit and select Open Scripts Folder (or just open BBEdit's BBEdit Support folder, Scripts subfolder). Open the sample scripts in Script Editor and play with them.

BBEdit Command Line Tool

When you run BBEdit for the first time, you are asked if you'd like to install the BBEdit command line tool. You definitely want to do this. The BBEdit command line tool is a Unix binary that passes data passed to it on to BBEdit. A few examples will help make this clear.

Launch Terminal. Type this command:

bbedit /usr/include/sys*.h

The BBEdit command line tool will launch BBEdit and open the files syslog.h and sysexits.h. For folks that are used to using text editors like vi and emacs will be delighted to have this powerful alternative to edit their Unix files. To take this one step further, emacs fans can go to the BBEdit menu, choose Preferences, select the Editing:Keyboard pane, then check the Use Emacs Key Bindings checkbox.

Here's another example. Type this command:

ls -l | bbedit

This command will do a long listing of the contents of the current directory, then use the Unix pipe tool (|) to send the results of that command to a BBEdit window. Beautiful!

Now try this one:

Man bbedit | bbedit

This will bring up the man-page for the bbedit command line tool in a BBEdit window. Worth a quick read, just to see what else you can do.

HTML Markup Tools

By far, one of the most common uses for BBEdit is to create and edit HTML. BBEdit is a great text editor, and you've probably seen the various menus that let you automatically construct and insert the various HTML tags in your document. You've probably also seen BBEdit's color coding of those same tags. But there's a bit more to the picture.

Start by selecting New HTML Document... from the File menu. A form appears that lets you specify a number of defaults for your document. Figure 6 shows a form I filled out to create my sample HTML doc.


Figure 6. Creating a new HTML document.

Once I clicked OK, a new editing window appeared, containing this HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>Dave's BBEdit Demo</title>
   <meta name="generator" content="BBEdit 8.0">
</head>
<body>

</body>
</html>

You should be able to follow along and see the connection between the various elements in the form and the actual HTML code that was generated.

Now find a picture on your hard drive somewhere and drag its icon onto the BBEdit window, preferably between the <body> and </body> tags. The dialog shown in Figure 7 will appear. Fill it in as you like, then click the Insert button.


Figure 7. Editing the <img> tag from a drag-and-drop operation.

Here's the <img> tag that was created from the dialog in Figure 7:

<img src="file://localhost/users/davemark/desktop/fur.jpg" alt="Picture of Fur" 
width="1600" height="1024">

Now for the coolest part. Click on the Markup menu and select Preview in BBEdit. A new window will open previewing the HTML you just created. BBEdit also allows you to preview in any browser you have installed on your hard drive. With this Preview capability, you can make changes to your HTML, preview it to see how it lays out, then edit and save and preview again.

If you've got modules like PHP installed on your local machine, you'll want to go to the BBEdit menu, choose Preferences, then select the HTML Web Sites pane. Double-click on the Untitled Site and edit the dialog shown in Figure 8.


Figure 8. Creating an HTML Web Site in the BBEdit Preferences.

Fill in the fields that describe the web site you are editing. If you are serving off your local machine, be sure to check the Use Local Preview Server checkbox. If it works on your local machine, BBEdit will take advantage of it. Serving pages locally means you don't have to edit and save files over the network. You can debug your entire site using BBEdit for editing and for preview. If you play with add-on modules like PHP and mySQL and you've not set up your own Mac as a local server, you should absolutely explore this option. A huge time saver.

The Doc Window

When you open multiple documents in Word, you get an individual window for each open document. When you open multiple documents in BBEdit, the documents are all listed in a drawer on the right side of the main editing window. Figure 9 shows an editing session with the documents drawer open, listing all the files currently open in BBEdit.


Figure 9. The document drawer.

Notice that the name of the currently edited document is in bold in the documents drawer. The diamond next to a doc indicates that it has not yet been saved. You can drag documents into and out of the documents drawer. If you look closely at Figure 9, you'll see that the doc being edited is a pdf. I dragged the pdf file from the desktop into the documents drawer and the pdf code appeared in the editing window. Pretty interesting stuff.

Drag a .jpg file onto the drawer and BBEdit will open a new window containing the image. Note that in this case, the .jpg appears in its own unique window and not as part of the documents drawer's "set". Drag a text doc (even an html, .rtf or .pdf, anything text-based) onto the doc and the document is added to the set.

Note the action popup menu in the upper-left corner of the documents drawer. You can use this menu to create a new, empty doc, close the current doc, or open the current doc in a new window, thus creating a new doc set. You can even drag docs between doc drawers, moving documents between sets.

You can open and close the doc drawer by clicking on the drawer icon in the upper-right corner of the main editing window. You can close individual docs by clicking on the x to the right of the appropriate doc name in the drawer.

You can also move between documents in a set by selecting the doc from the drop-down menu in the status bar, just below the icon bar in the main editing window or by clicking the left or right arrows in the navigation bar to move up or down the doc list.

Text Factory

One of my favorite features in BBEdit is the Text Factory. Text Factory? You'll see. Go to the File menu, select New, then Text Factory from the submenu. An untitled factory window will appear (see Figure 10).


Figure 10. A new, untitled Text Factory.

Your goal here is to build a set of rules that you can then apply to document's text. For example, in the default Text Factory in Figure 10, the Change Case operation is selected. Obviously, we'll use this operation to change the case in a document's text. If you click the Options... button to the right of this operation, you can set the specific Change Case options. As you can see in Figure 11, we'll set the specified text to ALL UPPER CASE.


Figure 11. This pane appears when you click the Options... button for the Change Case rule.

Click the + button to add a new operation, - to delete the current operation. Figure 12 shows the list of operations you can choose from.


Figure 12. The list of Text Factory operations.

Once you are happy with your Text Factory, you can click the Choose... button at the top of the window to select files on which to operate and click the Options... button to customize the search, then click the Apply button.

Alternatively, you can save your Text Factory (just as you would any other document) as a file on your hard drive. Once saved, click in the doc you want to change and select Apply Text Factory... from the Text menu. When prompted, choose the saved factory and it's operations will be applied.

Till Next Month...

There is just so much to write about, I could go on forever. Problem is, I've already way overstepped my page limit. Sorry folks, got carried away. But before I go, here are a pair of quick secrets that I think you'll enjoy.

I find the first one incredibly useful. Pick a doc to edit, then hold down the option key. The cursor should turn into a plus sign. Click and drag and BBEdit will create a rectangular selection. Try it, you'll like it.

To access the second secret, select About BBEdit from the BBEdit menu. Wait a few seconds. The about box will start to scroll. If you don't want to wait and you have a scroll wheel mouse, you can scroll the about box by hand.

But that's not really the secret. Hold down the command key and click on the about window's title. Cool! It's a very secret menu. Select each of the items and enjoy. See you next month!


Dave Mark is a long-time Mac developer and author and has written a number of books on Macintosh development, including Learn C on the Macintosh, Learn C++ on the Macintosh, and The Macintosh Programming Primer series. Dave's been busy lately cooking up his next concoction. Want a peek? http://www.spiderworks.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.