2001/07/17

Y'all know that I love baseball, and so does Sheila. So I'm one lucky guy.

But -- as if the luck could get even better -- my sister, who also lives in Ballard, loves baseball too.

I wrote my first shell script yesterday. Linux gurus will laugh -- but that's alright. Some people who read this site are OS X newbies, so I figured I'd share this.

I wanted a simple way to take notes. I always have an ssh window to my OS X machine open, no matter what machine I'm on. So I want to store my notes on that machine.

It should be easy to create and/or edit a note, and they should always be stored in a directory named Notes in my home directory.

So I wrote a command that allows me to type ~/.note notename, where notename is the name of a new or existing note.

What the script does is open an existing note for editing, or create a new note with that name.

It's very simple. Here's the code:


#!/bin/tcsh

# Create a new note or edit an existing

# note and save it in the ~/Notes directory.

# Brent Simmons 07/16/01

if ($# != 1) then

    echo "Please supply a note name."

    exit 1

endif

/usr/bin/emacs  "~/Notes/$argv"

exit 0

It's a file in my home directory named note. I made it executable with this command: chmod u+x ~/note.

Here's how the script works:

The first line, #!/bin/tcsh, specifies the shell to execute the script. tcsh comes with OS X.

The lines that begin with a # are comments.

The if block checks that there is one and only one parameter. The variable $# is always the number of parameters. If there is less than one or more than one parameter, the script reminds me that I need to supply a note name. Then it exits with the status code 1 -- a non-zero status code means that something went wrong.

If the script gets past that test, then it simply tells Emacs to open a file in the ~/Notes/ directory that has the name of the note. $argv is the parameter I typed on the command line.

If the file already exists, then Emacs opens it. If it doesn't exist, Emacs creates a new file.

Very simple.

To see a list of all my notes, I simply type ls ~/Notes.

"tinyshoe.gif"

I'm going to the ball game! It's an afternoon game vs. the Arizona Diamondbacks.

Go Mariners!

I love it when Matt Neuburg answers a question with "You're working way too hard. :-)"

I've said it before, and it bears repeating -- if something in Frontier seems really insanely difficult, it's probably because you're not doing it the easy way.

Now, that's not always true, but it's true pretty often, enough to make this a useful rule of thumb.

"bluebox.gif"

I'll (try to) listen to tomorrow's MacWorld keynote by Steve Jobs live.

I really really really want to hear about OS X performance. I don't care about new flat-screen iMacs, hand-helds, new G4 enclosures, CD burning, all that stuff. Nope, totally don't care.

I just want OS X to get faster. (Why? Because I dig it.)

17 Jul 2001

Archive