Mac'ing progress

Volume 10, Issue 85; 27 Aug 2007; last modified 08 Oct 2010

A week into my Mac, I think it's a net win (remind me to write about the joys of 10,000+ images in LightRoom), but it's not perfect. Nothing is, so that's ok.

As I suspected, the single most annoying thing about the Mac, without question, is click-to-focus. I understand that, like Emacs vs. VI or Python vs. Perl, this is really a question of preference not correctness. Except that, just as Emacs is the One True Editor, so focus-follows-mouse is the One True Policy. But I digress.

I find it particluarly annoying because it's not actually used consistently. The little red, yellow, and green buttons in the window title bar behave as if focus-followed-mouse. And if you “click to focus” on a terminal window and your click happens to be on the scroll bar, the scroll moves. That's probably a bug, but still, it's not click-to-focus, is it?

One argument for “click-to-focus” is that the current application determines the screen's menu bar. If the policy was focus-follows-mouse, attempting to move the mouse from the current application to the menu bar might cross over other application windows and consequently change the menu bar. Fair enough. But is that menu bar at the top of the screen really a good thing anyway? I'd be perfectly content with “focus-follows-mouse”/“click-changes-menu-bar”, if anyone asked.

On the other hand, the track pad has turned out not to be such a big deal. I'm getting used to it. Last time I had the ThinkPad up, I found myself using the track pad instead of the pointing stick, so that must be progress of a sort.

The only other point of note is that I've had three kernel panics. That's three more in a week than I've had in the past couple of years. But maybe I've got that under control now. I think I was missing a driver update at first and I think the panic that resulted from that mangled the disk. Now I've got the latest updates and I've fixed the disk, so here's hoping.

Most of the other things that are bothering me now are off in the margins. One thing I'd like to find is the command-line equivalent of

$ xterm -bg wheat -fg black -geometry 80x10 -e exec ssh hera

I still feel a little bit like a mostly command-line guy in a mostly point-and-click world, but mostly it's ok.


Heh, I'm not sure that you really do want to know the equivalent of that! As far as I've found, the only way to that is with one of open-x11(1), which doesn't seem to want to allow you to pass arguments, or AppleScript. For AppleScript, you have to have a script, say usershell.scpt, that looks a little like:
      on run argv
	set server to item 1 of argv
	tell application "Terminal"
		with timeout of 10 seconds
			do script with command "ssh " & server
			tell window 1
				set background color to "black"
				set cursor color to "green"
				set normal text color to "yellow"
				set bold text color to "red"
				set number of columns to 80
				set number of rows to 10
			end tell
		end timeout
	end tell
end run
and then you run that with: osascript usershell.scpt hera Horrible, isn't it?
—Posted by Ceri Davies on 28 Aug 2007 @ 10:05 UTC #
Hmm. This lead me to try using #!/usr/bin/osascript to write a script, which... sadly, does not work. You could, however, use a shell script combined with the following approach to do something moderately more powerful, using getopt and friends in sh. Put that somewhere convenient, or in a shell function, even, and you now have a rather generic xterm-alike command.

# Smarter approach would be: parse out args using getopt and friends


shift 4

osascript <<__END__
on run argv
   tell application "Terminal"
      with timeout of 10 seconds
         do script with command "$*"
         tell window 1
            set background color to "$bgcolor"
            set normal text color to "$fgcolor"
            set number of columns to $width
            set number of rows to $height
         end tell
      end timeout
   end tell
end run
—Posted by John Prevost on 28 Aug 2007 @ 11:53 UTC #
Thanks, Ceri! That moves "AppleScript" up on the list of things I must learn. In any event, that was the hint I needed. Here's what I cooked up:
#!/usr/bin/perl -- # -*- Perl -*-

use strict;
use Getopt::Long;
use English;

my $usage = "$0 [-bg color] [-fg color] [-geometry geom] [-e] command\n";

my $width = undef;
my $height = undef;
my $xofs = undef;
my $yofs = undef;
my $bgcolor = "white";
my $fgcolor = "black";
my $cucolor = "gray"; # FIXME: make this dynamic
my $bocolor = "red";  # FIXME: make this dynamic
my $command = "";
my $geometry = undef;

my $result = GetOptions ("bg=s"       => \$bgcolor,
                         "fg=s"       => \$fgcolor,
                         "geometry=s" => \$geometry,
                         "e=s"        => \$command);

die $usage unless $result;

if (defined($geometry)) {
    if ($geometry =~ /^(\d+)x(\d+)([\+\-]\d+)?([\+\-]\d+)?/) {
        $width = $1;
        $height = $2;
        $xofs = $3;
        $yofs = $4;
    } else {
        die "Invalid geometry: $geometry\n$usage";

$bgcolor = getcolor($bgcolor);
$fgcolor = getcolor($fgcolor);
$cucolor = getcolor($cucolor);
$bocolor = getcolor($bocolor);

# FIXME: what about arguments that need to be quoted
$command .= " " if $command ne '';
$command .= join(' ', @ARGV);

open (SCRIPT, "| osascript -");
#open (SCRIPT, ">-");
print SCRIPT "on run argv\n";
print SCRIPT "  set RGBfg to $fgcolor as RGB color\n";
print SCRIPT "  set RGBbg to $bgcolor as RGB color\n";
print SCRIPT "  set RGBcu to $cucolor as RGB color\n";
print SCRIPT "  set RGBbo to $bocolor as RGB color\n";
print SCRIPT "  tell application \"Terminal\"\n";
print SCRIPT "    activate\n";
print SCRIPT "    with timeout of 10 seconds\n";
print SCRIPT "      do script with command \"exec $command\"\n";
print SCRIPT "      tell window 1\n";
print SCRIPT "        set normal text color to RGBfg\n";
print SCRIPT "        set background color to RGBbg\n";
print SCRIPT "        set cursor color to RGBcu\n";
print SCRIPT "        set bold text color to RGBbo\n";
print SCRIPT "        set number of columns to $width\n"
    if defined($width);
print SCRIPT "        set number of rows to $height\n"
    if defined($height);
print SCRIPT "      end tell\n";
print SCRIPT "    end timeout\n";
print SCRIPT "  end tell\n";
print SCRIPT "end run\n";
close (SCRIPT);

sub getcolor {
    my $color = shift;
    my $db = "/usr/X11R6/lib/X11/rgb.txt";
    open (RGB, $db) || die "Cannot read color list: $db\n";
    my $match = (grep(/^\s*\d+\s+\d+\s+\d+\s+$color$/, ))[0];
    die "Unknown color: $color\n" if !defined($match);
    $match =~ /^(\d+)\s+(\d+)\s+(\d+)\s+/;

    my $r = int($1/255.0*65535.0);
    my $g = int($2/255.0*65535.0);
    my $b = int($3/255.0*65535.0);

    return "{$r,$g,$b}";
Bit of a hack, but gets the job done!
—Posted by Norman Walsh on 28 Aug 2007 @ 01:01 UTC #

Heh. Great minds, John :-)

—Posted by Norman Walsh on 28 Aug 2007 @ 01:03 UTC #

The way I do things like this, is to set up a Terminal window the way I want it to look, and then save it. When you do a save in Terminal, it allows you to specify a command to run instead of the default shell. Then the command line is:

open path-to-term-file

If you save it into ~/Library/Application\ Support/Terminal it will appear in the "Library" item in Terminal’s File menu. Also, this file is an XML document (of sorts—I think it contains characters that aren’t legal in well-formed XML) and you can modify it with any text editor.

—Posted by Curtis Pew on 28 Aug 2007 @ 03:06 UTC #

If you want an argument for the menu being attached to the top of the screen you should read up on Fitts' Law.'_law

The top of the screen effectively makes the hight of the target area infinite and hence the time to acquirement is very low. You can literally throw your mouse upwards in the knowledge that it will land on the menu bar.

—Posted by Noah Slater on 29 Aug 2007 @ 03:48 UTC #

Nice, I'll update my scripts; never did get around to spending time on it.

—Posted by Ceri Davies on 29 Aug 2007 @ 10:27 UTC #

As an alternative to click-to-focus, you can use F9 + [tab or cursor keys] to choose the focus from your keyboards. If you use F10 it will give you the choice of windows within the application you are working on.

—Posted by Wataru on 29 Aug 2007 @ 12:19 UTC #

Hmm, Wataru. F9+[tab or cursor keys] has no effect on my desktop.

—Posted by Norman Walsh on 29 Aug 2007 @ 03:31 UTC #

Oddly, Curtis, the "open /path/to/file.term" trick doesn't work for me. I fully expected it to, but in fact, nothing happens.

—Posted by Norman Walsh on 29 Aug 2007 @ 06:51 UTC #

Norman, check "System Preferences --> Dashboard & Expose". It has "Keyboard Shortcuts" section. My setting for "All windows" is F9 and "Application windows" is F10. I thought they were the default but maybe not. Try the keys with your settings, they shoud work.

—Posted by Wataru on 29 Aug 2007 @ 11:19 UTC #

Hmm… at first I was worried because I'd never actually used open with a .term document (as a long time Mac user I’m pretty comfortable with a mouse, so I use the Library menu I mentioned) but to make sure I tried it and it worked for me. When you look at your .term documents in the Finder, does it say their type is "Terminal"? The other thing you might try is to use the Console utility to see if a message is being written there.

—Posted by Curtis Pew on 30 Aug 2007 @ 10:22 UTC #

Hmm. Well, for whatever reason, it works today. But I swear it didn't yesterday. I have rebooted since then, but I can't say what really changed.

—Posted by Norman Walsh on 30 Aug 2007 @ 11:12 UTC #

Hey Norm - I take it you got a MacBook since you were talking about the track pad.

First thing I did when I got my Mac was set it to turn the track pad off when I've got a mouse up and running, and since I rarely take the silver surfboard anywhere, the track pad is pretty much always in disabled mode.

My biggest trip up has been the need to use the fn key with all of the F keys and the Page direction keys. so the first thing to try in the event of shortcut key failure is adding the fn key to the mix.

Have you installed oXygen yet? I have to say, it looks gorgeous, and the screen geometry and functionality finally make sense to me!

—Posted by Jean K. on 15 Sep 2007 @ 08:55 UTC #