oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Unix Gems for Mac OS X
Pages: 1, 2, 3, 4

Now that your processes are running, you need some way to switch between windows. There are a few ways to accomplish this. To toggle between the current window and the one you were previously using, type Ctrl-a Ctrl-a. To switch to the next window type Ctrl-a n, or Ctrl-a p for the pervious window.

You can also switch windows using screen's window list. When you type Ctrl-a, screen displays a list of active windows. To switch to a window, use the arrow keys (or vi-style, with j and k), to select the window and press Return.

As you can see, screen assigns each virtual window a unique ID number. The first window is tagged with ID 0, indicating it's the first window. As you create new window, screen tags then with ascending IDs.

If you add the following commands to your .cshrc file, your prompt will be prefixed with its screen window ID.

	unset prompt
	if ($TERM == screen) then
	  set prompt = "(%{#$WINDOW%}) % "
	  set prompt = "% "

Window IDs are OK, but it's easier to navigate if you use window names instead. To name a window, type Ctrl-a A, backspace over the old title, and enter the new name at the prompt. Now when you list the windows (Ctrl-a), you can refer to them by name rather than ID.

Another way to navigate windows is by typing Ctrl-a followed by the window ID. Finally, adding the command:

  caption always "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

to your .screenrc file displays all windows at the bottom of the screen.

Using just this knowledge, I'm sure you can imagine all sorts of useful things to do with screen. For example, what if you log into several remotes machines daily. Using screen, you can set things up once and leave them open indefinitely, all in one Terminal window.

At this point, you might be saying to yourself all this sounds fine, but it still requires lots of typing if I exit screen. This is where your .screenrc file comes in. As you read earlier, this file contains settings that you use to customize screen.

A common technique is to create different screenrc files and have screen read the one you want at startup using the -c command-line option. The -c option tells screen to override the default configuration file $HOME/.screenrc with the specified file.

You can use the following screenrc file to simplify the previous example.

# ---- Example screenrc file for creating windows and processes.
# Create a window and use tcsh.
screen tcsh
# Turn off the startup message.
startup_message off
# Set the caption to the active windows. 
caption always "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"

# New screens for various processes.
screen -t emacs 1 emacs
screen -t pine 2 pine
screen -t lynx 3 lynx
screen -t news 4 slrn                                        

Now that you understand the basics, let's look at a powerful feature of screen -- detaching and reattaching from/to a screen session. Staying with the pervious example, you should have a screen session running emacs, pine, lynx, and slrn.

Switch to any of these windows and type Ctrl-a d. This command detaches screen from this terminal and returns you to your original shell prompt. When detaching, screen prints a message to your shell indicating that the session was detached.

Now, go to a different machine, open a shell, ssh to the machine running screen (the one you just detached from), and type:

% screen -r

The -r option instructs screen to reattach to the session. Just like magic, your session is back up and running, just like you never left it. Try switching between windows to convince yourself that things are working.

To exit screen simply exit each program and the window you created. At any point, you can type Ctrl-a ? for a list of the available screen commands and their bindings.

The following table lists some of the more useful screen commands. For a complete list, see the screen man page.

Create a new window Ctrl-a c
Toggle between windows Ctrl-a Ctrl-a
Switch to the next window Ctrl-a n
Switch to the previous window Ctrl-a p
Switch to the window id Ctrl-a k (k = window id)
List all windows Ctrl-a "
Name a window Ctrl-a A
Help Ctrl-a ?
Detach from a session Ctrl-a d
Reattach to a session screen -r

Take a look at the screen man page as well as the articles listed in the Resource section. They cover many of screen's other features, including copying and pasting between windows, setting up key bindings, and sharing a screen session between different users.

Remind -- A Sophisticated Reminder Service


Palm devices are everywhere. They're used to track contacts and schedules, enter information into databases, access email and the web, and play games. For scheduling and dealing with your calendar and contact list, Mac OS X come with software you can use to handle these things at no cost.

There are a few calendaring programs that you can use under Mac OS X. The simplest cal. The cal program displays a text-based calendar of the current month, or any other month or year that you specify.

The cal program generates read-only calendars. They're great for viewing, but not for scheduling your own events.

Another useful program is the Unix calendar utility. This utility enables you to keep a list of dated activities in a file and print out today's events using the calendar program.

The cal and calendar work great for general calendaring, but if you want more control and features, you will want to use Remind.

Remind is a reminder service with lots of options and features. Here's how it works. First, you list your reminders in a file in your home directory called .reminders. Each entry represents a calendar event or reminder. Once you add entries to the file, you run the Remind command to process the file and produce a formatted calendar.

Depending on the options, Remind will output events from a reminder list to a text or Postscript-formatted calendar.

Let's take a look at how to add events to your reminders file, as well as generating reminders. You add an entry in the reminders file for each event you would like to add to your calendar.

The following figure shows examples of the different types of events you can place in your .reminders file. Some of these are original and some I've collected from various web sites and articles.

# Example .reminders file.

# Single message.
REM 31 October 2002 MSG 4:00 Message.

# Last Monday of a month.
REM Mon 1 --7 MSG Last Monday of a month.

# The OMIT line tells Remind that 1 July is a holiday, and 
# it also prints a nice message on that date..
OMIT 1 July MSG Canada Day.

# The SKIP token in the REM line tells Remind to skip the 
# reminder if it falls on a holiday.
REM Thursday SKIP MSG Meeting.

# The AT keyword introduces an "AT clause." The 17:00 means 
# that the trigger time is 5:00 PM. The +15 means Remind 
# starts carping at you fifteen minutes ahead of time, and 
# the *3 means it annoys you every three minutes.
REM Mon Tue Wed Thu Fri AT 17:00 +15 *3 MSG Go home!

# Print message every week.
REM 13 March 2001 *7 MSG 4:00-5:00 AI seminar

# Every January 1, and for the five preceding days, 
# it will print the phrase 'My Birthday'. This is not 
# quite what you want, though: December 26, 27, 28, 29, 
# etc., are not your birthday.
# REM 1 Jan +5 My Birthday

# This will add 'in 5 days', 'in 4 days', 'tomorrow', 
# 'today' to the end of the phrase. However, if you 
# also use Remind to print a calendar, that day's entry 
# will have the phrase 'My Birthday today'.
REM 1 Jan +5 My Birthday %b

# This will still, when you simply ask for your day's reminders, 
# print 'My Birthday in 5 days', etc, but on the calendar 
# it will simply print 'My Birthday' on the correct day.
REM 1 Jan +5 %"My Birthday%" %b

# This will print, on the first Monday on or after the 
# 15th, the phrase 'Writer's Guild 6:30 PM'. 
# The third Monday can be no earlier than the 15th, 
# because the 1st Monday can be no earlier than the 1st, 
# making the 2nd Monday the 8th and the third the 15th. 
# By specifying a date of 'Monday 15', Remind knows to 
# look for the first Monday on or after the 15th of the month.
REM Monday 15 Writer's Guild 6:30 PM

# Similar to the above, but we've specified a more specific 
# date: the first Sunday in April.
REM Sunday 1 April MSG Spring Forward

# On November 27, 2001, and every two days after, you'll see 
# the phrase 'Feed the Fish'.
REM November 27 2001 *2 MSG Feed the Fish

# This will do the same as the above, until December 25 2001, 
# after which it 'expires'. It will no longer print.
REM November 27 2001 *2 UNTIL December 25 2001 MSG Feed the Fish

# However, you don't want to print 'Vacation' on Saturday 
# and Sunday, because that's silly.
REM July 22 2001 *1 UNTIL July 29 2001 MSG Vacation

There are many ways to output reminders. The simplest is to run the rem command. You can also add the command to your .cshrc file (if you are using tcsh) so each time you open a new shell, you are notified of todays events.

Pages: 1, 2, 3, 4

Next Pagearrow