Use a Command-line AirPort Tool

Today's Best Tech Deals

Picked by PCWorld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

As you may (or may not) be aware, Apple often includes command line versions of its applications--so for many things you can do in the GUI, you'll find there's a command line equivalent. Off the top of my head, for instance, there's screencapture (for grabbing screenshots), systemprofiler (aka System Profiler), and (in 10.5, anyway) networksetup (System Preferences' Network panel). Today, we'll add one more to the list--airport, for controlling your machine's AirPort connections from Terminal.

While Apple provides a couple of GUI methods for working with AirPort connections (the AirPort Networking System Preferences panel and the AirPort menu bar icon), sometimes it's nice to have a command-line alternative.

Unlike the other examples on my list, the airport command is pretty well buried; to find it, you'd have to navigate to the top-level /System -> Library -> PrivateFrameworks -> Apple80211.framework -> Versions -> A -> Resources folder. Since that's a real pain to do every time you want to use the program, here's a simpler solution: we'll create an alias to the command (basically much like an alias in the Finder) in your user's .profile file (located in your user's home directory) to make it simple to access. (You Unix-savvy types could alternatively create a symbolic link somewhere on your path, but I'll leave that as an exercise for the reader.)

Your user's .profile file is loaded each time you open a Terminal window; it contains a series of commands that help configure your Terminal session. This file doesn't exist by default, so if you've got one (ls -la ~/.profile will show you whether you have one or not), it means you've done something in the past to create it. Whether you have such a file or not, however, the following instructions will work in the same manner.

To create an alias to Apple's built-in airport program, open Terminal and type nano ~/.profile and press Return. nano is a text editor in Terminal; if it opens to a blank screen, that means you don't currently have a .profile file. If you see text (other than the nano title bar and menus at the bottom of the screen), then you obviously do have a .profile file. If that's the case, just use the Down Arrow to move the cursor down to the end of the file; if your screen is blank, you can skip that step.

Once the cursor is on a blank line, enter the following command:

You can replace apinfo with whatever name you'd like to use for your version of the command. To save your changes, press Control-X (for Exit), Y (for Yes, to save the changes) and then Return (to accept the displayed filename and path).

To test your new command, open a new Terminal window and type apinfo -help (or whatever you named the command). You should see the output for the airport command's help page:

Although there are many options, the two I find most useful are -I (to display information on the current AirPort connection) and -s (to scan for wireless networks).

In particular, I use apinfo -s to get a list of nearby wireless networks--the output includes not only the name of the network, but it's signal strength (the RSSI column in the output) as well as what type of security it's running:

As noted in our Leopard survival guide, you can see this same information by using the Option key with the AirPort menu bar icon. However, this will only show you information on each network one at a time; the Terminal command lists all the networks in one convenient table.

You may not need or want to use the AirPort Terminal program every day, but having it available via an easy-to-use alias means it's there when you need it.

This story, "Use a Command-line AirPort Tool" was originally published by Macworld.

Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our affiliate link policy for more details.
Shop Tech Products at Amazon