13.1. TerminalTo interact with Mac OS X's Unix core, you use the Terminal program, located in your Applications Utilities folder. When you launch that program, you see a pretty meager window, with a line of text and a cursor for you to enter programs' names (Figure 13-1).
This line of text is known as a command promptor, in casual geeky conversation, just a prompt. You type the name of a program here and press Enter (or Return) to run that program. When a new prompt appears, Unix is ready to accept a new program's name.
If you wanted to run the uptime program, for example, you'd type this: Adam-Goldsteins-Computer:~ goldfish$ uptime Once you pressed Enter, you'd see a result like this: 11:27 up 27 days, 17:50, 1 user, load averages: 0.50 0.45 0.43 That information tells you: what time it is; how long your computer's been running without restarting; how many users are on your computer right now; and how hard your processor is working (on a scale from 0 to 2). Of course, if you want to check that information oftensay, so you can brag to your friends that your Mac's been running for a month straightit's kind of annoying to enter uptime in Terminal every time you want to check your Mac's status. Luckily, Terminal supports a special AppleScript command, do script, that can greatly automate the process of running Unix programs. Here, for example, is a script to run uptime from AppleScript: tell application "Terminal" activate do script "uptime" --Here's where you specify the Unix program end tell When you run that AppleScript, Terminal comes forward and runs the Unix uptime command for you.
13.1.1. Changing System SettingsThere are far more sophisticated programs you can run in Terminal, too. For instance, you can display a floating blue Exposé button (Figure 13-2) by running the following command in Terminal: defaults write com.apple.dock wvous-floater -bool true
You won't see the blob, however, until you quit and restart the Dock. You can do that in one of two ways:
Once the Dock restarts, your blob appears onscreen, ready for action.
man defaults
Of course, you can package your blob-creating Unix command in an AppleScriptso you can share the blobby convenience with all your friends, for example: tell application "Terminal" activate do script "defaults write com.apple.dock wvous-floater -bool true" end tell tell application "Dock" quit --Restart the Dock end tell
13.1.2. Unix Text EditingIf you come from the graphical world of Mac OS X, the idea of a Unix text editor probably strikes you as pretty odd. In a Unix text editor, you can't use the menu bar or mouse to edit text, you can't drag-and-drop sentences to different places, and perhaps worst of all, you can't spell check your writing. Why on earth would people subject themselves to this? Power, that's why. For people who spend their days writing computer programs, Web pages, and the like, Unix text editors offer all sorts of power-user features: simple looks, extreme customizability, and tons of keyboard shortcuts, for example. Even non-geeks might want to use Unix text editors on occasionso they can edit system files, for example. Unfortunately, there's no simple way to open a text file from the graphical side of Mac OS X in the Unix side. The best you can do is type the name of the text editor in Terminal, followed by the path to file you want to open, like this: pico ~/Desktop/CheeseDoodles.txt That, of course, would open your Home Desktop CheeseDoodles.txt file in the Unix text editor named pico.
Luckily, you can use AppleScript to simplify the process of opening a file in pico (or any other Unix text editor, for that matter). That way, you can edit your text files the old-fashioned wayin the Terminalwhich many power users prefer for its total reliance on the keyboard (and total avoidance of the mouse). This script gets you started: --Part 1: on run display dialog "Drag files to my icon to open them in pico." end run --Part 2: on open draggedItems --Part 3: repeat with currentItem in draggedItems --Part 4: set unixPath to the POSIX path of currentItem --Part 5: set unixString to ("pico " & unixPath) --Part 6: tell application "Terminal" activate do script unixString end tell end repeat end open
Here's how the script works:
Now, if you ever feel the need to open some text files in Terminal, just drag the files to your script's icon. For easy access, you can even store your script in the Dock, so pico is never more than a file-drag away. |