oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

BBEdit: Its Unix Support Doesn't Suck Either, Part 2
Pages: 1, 2, 3


Another useful feature to check out are BBEdit glossaries. Glossaries enable you to insert saved text into your document. You access glossaries by choosing Window->Palettes->Glossary. This command opens a floating window that displays a list of available glossaries.

BBEdit stores glossaries in the BBEdit 7.1/BBEdit Support/Glossary folder. Each glossary is stored in a separate folder, named for the glossary. Each glossary item is stored in a separate file, stored within its set folder. Each file contains the text that BBEdit inserts into your document.

To create your own glossary, create a new folder within BBEdit 7.1/BBEdit Support/Glossary. Name the folder the name of the glossary. Next, create a new file within BBEdit and enter the text you wish to insert. Save the file into the folder you just created, naming the file with the name you wish to appear in the glossary item list. BBEdit adds the new glossary to the glossary Set pop-up menu.

To use a glossary, select it from the Set pop-up menu. Next, either select a glossary item from the list and click on the Insert button or double-click on a glossary item. For example, selecting the C Source.cp glossary and double-clicking on the FileHeader.c item will paste the associated text at the current cursor point.

If you like, you can assign a key binding to a glossary item by clicking on the item, choosing the Set Key... button, and typing the key sequence.

BBEdit glossaries also support substitutions. To use this feature, you insert defined placeholders into your glossary text. When BBEdit processes the glossary item, it replaces each placeholder with the corresponding substitution text.

For LaTeX users, there are glossaries for both BibTeX and LaTeX.


The final thing I would like to mention is BBEdit's AppleScript support. For those not familiar with AppleScript, it's a language specifically designed for interacting with the Macintosh OS and its applications. AppleScript excels at performing various kinds of process automation.

With AppleScript, your Macintosh becomes an array of services encapsulated in various application programs. For example, programs such as BBEdit support text editing and manipulation services; Fetch and Safari support network and web services; and others offer multimedia and audio facilities.

In order for a script to use the services of a program, the author of the program must write it in a way that explicitly makes its application services available to clients. Programs written in this way are called AppleEvent-enabled programs, meaning they can respond to requests from other programs by exposing services to the outside world.

For example, suppose you have a text document and wish to change all occurrences of the word "this" to "that." To accomplish this, you launch BBEdit, open the file, and choose the BBEdit service that replaces all occurrences of the word "this" with "that." You can think of each of these actions (opening a file, searching and replacing text, and so on) as an application service that you access through the program's GUI.

Next, suppose you have replaced all occurrences and saved the file from within BBEdit. Now, you need to transfer the file to a remote host. Unless BBEdit supports this service, you are stuck. In this case, you need to use another program, such as Fetch or a secure copy command (scp) client, to send the file to the host.

With AppleScript, you are free to write scripts that use and combine the services of many programs. Using the previous example, all you need to do is write an AppleScript that combines the text manipulation services of BBEdit and the network services of Fetch. Now, in one script, you can automate and solve both tasks.

If you keep expanding this concept, you can see that the programs that come with your Macintosh, as well as any AppleEvent-enabled programs you add to the system, become participants in this game. You can accomplish many complex tasks that were otherwise impossible by using AppleScript to knit together application services.

BBEdit is a scriptable application, so you can call on its services from your AppleScripts. Within BBEdit, you access scripts from the Scripts menu. This menu, much like the Shebang menu, provides access to AppleScript services and scripts.

Here's a simple example of using an AppleScript within BBEdit to access an online dictionary and thesaurus. To use the script, place it in the BBEdit 7.1/BBEdit Support/Scripts folder. Next, choose the word you wish to look up, and select Scripts->LookupWord.

The script takes the selected text and passes it to Sherlock, an application that comes with Mac OS X and is used to get information from web services on the Internet. Sherlock looks up the word and displays the results.

Like filters, AppleScripts are especially convenient when you assign key bindings to the scripts. This enables you to run the script by pressing the assigned key binding. To do this, select Window->Palettes and select Scripts. BBEdit displays a floating window that holds your AppleScripts. Select the script from the list, click on the Set Key... button, and enter the key binding.

For more information on using AppleScript with BBEdit, see the BBEdit manual.

Final Thoughts

This concludes our look at BBEdit's Unix support features. You have seen how to run BBEdit from the command line, use shell worksheets, and write and use filters and scripts. In addition, we took a quick look at some of BBEdit's other useful features, including plugins, glossaries, and its AppleScript support.

If you are looking for a solid, extendable Mac-OS-X-based editor that supports integration with UNIX, give BBEdit a try. It's rock-solid, intuitive, extendable, and a pleasure to use. This article has focused on BBEdit's Unix support, but there are lots of other features to explore as well.

Good luck and as always, if you discover something new or have a cool way to use BBEdit, post it in the TalkBack section or send me an email.

Kevin O'Malley is a long time Macintosh and UNIX developer. His articles have appeared in Dr. Dobb's Journal, IEEE Internet Computing, and The Perl Journal, and he is the author of Programming Mac OS X: A Guide for UNIX Developers.

Return to the Mac DevCenter