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

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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.