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

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 »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »

Price Scanner via MacPrices.net

B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more

Jobs Board

Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
Top Secret *Apple* System Admin - Insight G...
Job Description Day to Day: * Configure and maintain the client's Apple Device Management (ADM) solution. The current solution is JAMF supporting 250-500 end points, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.