Thursday, December 16, 2004

Utility of the week: AppleJack

Through references in passing in a forum discussion about OS X software updates, I found out about a tiny but very useful open source utility called AppleJack. Running the utility installs a new command "applejack", which is hidden from normal system usage but available when booted in single user mode (i.e., with Command-S pressed down). [Most of the time, if your system is so messed up that you cannot boot graphically in OS X anymore, you will still be able to do single-user boot. You get a BSD-only text prompt, which makes Unix sysadmins go "aha!" and regular Mac users panic. "applejack" allows you to "jack up" your Mac and fix a "pantsher" [flat tire] without calling a garage mechanic :-)]

What it does is provide a simple text-based menu for a number of troubleshooting utilities which are part of OS X. Holding COMMAND-S down while booting, you will now see a line suggesting that you run "applejack". When you type "applejack" at the command prompt you will get the following options:
[1] Repair disks                                                                
[2] Repair permissions
[3] cleanup cache files
[4] validate preference files
[5] remove swap files
[6] reboot
[a] autopilot: steps 1-5 in sequence
[q] no thanks!
Steps [1] and [2] are basically the corresponding steps in "Disk Tools". [3]--[5] can be quite useful in getting a wedged or unstable system unstuck. [6] speaks for itself.

Note for sysadmins and other fellow geeks: the CMD-S have to be pressed on a keyboard DIRECTLY connected to the Mac. It won't work through a USB KVM switch (as I found out today ;-))

Tuesday, December 14, 2004

Resurrecting copy/paste

If you (like me) occasionally suffer from losing your ability to copy/paste after you've been logged in for a LOOOONG time, "aramis" at Mac OS X hints has the answer:
I may be an unusual case, but I have a repetitive problem with Apple's Paste Board Server (pbs) dying on a semi-regular basis. The main symptom is the inability to copy and paste between applications. Logging out or rebooting will fix the problem every time, but a less disruptive solution is to spawn a new copy of /System -> Library -> CoreServices -> pbs. Some apps will connect to the new server automatically, though many (notably Firefox and TextEdit) need to be quit and restarted before they start working normally again.

How can you tell if pbs is dead? Open a Terminal window and run:

ps x | grep pbs

If pbs is dead, you'll see something like:

350 ?? Z 0:00.00 (pbs)
22200 std R+ 0:00.01 grep pbs

If pbs is alive, you'd see:

350 p4 S 0:00.29 /System/Library/CoreServices/pbs
22200 std R+ 0:00.01 grep pbs

If you see (pbs) in parentheses, it's dead! Zombied to be technical. If you see the full path to pbs listed out, then pbs is running fine. If you see both, then chances are you've already restarted pbs manually at some point since you last logged out or rebooted.

If your pbs is dead, you can starte a new one. Just open a Terminal window and type:

nohup /System/Library/CoreServices/pbs &

The nohup keeps pbs running even after you close the current Terminal window. I got sick of restarting pbs myself, so I came up with the following script -- I named it newpbs, and keep it in /usr/local/bin:

#!/bin/bash

NEEDNEWPBS=`ps x | grep /System/Library/CoreServices/pbs | grep -v grep ; echo $?`

if [ "$NEEDNEWPBS" == "1" ] ; then
echo "PBS is dead. Starting a new one..."
nohup /System/Library/CoreServices/pbs > /dev/null &
osascript -e "tell application "Finder" to display dialog "Paste Board Server died and was restarted at `date`" buttons {"OK"}" > /dev/null &
fi

newpbs checks to see if there's a non-zombied copy of pbs running. If there isn't, it starts a new one and displays a dialog to let you know what happened. You can always comment out or remove the osascript line if you're rather not get the pop-up. In order to check for pbs' death every five minutes, I added this script to my crontab by running crontab -e, and adding the following line:

*/5 * * * * /usr/local/bin/newpbs

While I'm still trying to track down the process that's killing my pbs, at least this gives me some added convenience.

Saturday, December 11, 2004

TeX/LaTeX under Mac OS X

For scholarly papers, a fair number of us (yours truly included) still swear by the cross-platform LaTeX typesetting system rather than by Microzift Word or any of its competitors. (Often the feature we LaTeX-users love most about it is the one non-LaTeX users hate most: strict separation between content and formatting. LaTeX is basically a markup language like HTML, but with a kajillion more possibilities, especially in terms of mathematical typesetting and cross-referencing. A not-so-short-introduction can be found here.)

A comprehensive directory of LaTeX-on-the-Macintosh resources can be found here. The most popular Classic Mac OS implementation of LaTeX, TeXtures, is no longer being developed for Mac OS X: however, Mac OS X being basically a version of Unix, the most popular Unix implementation teTeX (which comes preinstalled on most Linux distributions) has been ported to Mac OS X virtually as soon as the latter came out. teTeX is open source.

The most convenient way to install it on a Mac OS X machine is probably Gerben Wierda's i-Installer for gwTeX. This is an interactive installer that will download all necessary pieces and install them. (The installations involve "compiling" the most common TeX formats.) If you choose this option, you should at minimum select the "TeX" and "GhostScript 8" packages. If you are planning to use figures in other formats than PostScript or Encapsulated PostScript, also grab "Freetype2", "libvmv and iconv conversion support", and "ImageMagick". You may also want to grab the "CM Super Fonts" package, which are fully scalable PostScript Type 1 fonts for the Computer Modern family (TeX and LaTeX's signature font).

Note that the "TeX" installation will take a nontrivial amount of time (5 to 15 minutes, depending on the speed of your CPU and hard disk). If you are concerned that the installation is stuck (in truth, it's doing plenty), turn on "Geek mode" and click on the "Subprocess output" tab. You'll see plenty of activity (probably gobbledygook if you're a (La)TeX novice).

Another alternative is to grab the "fat installer", a 60 MB download which already has the TeX and Ghostscript 8 packages bundled. A HTTP mirror is available here at Yale.

If you are an experienced TeX/LaTeX user and have accumulated a number of personalized style files/custom fonts/..., make a subdirectory ~/Library/texmf/ if it does not exist yet and install them in appropriate subdirectories there.

Now what you still need (unless you're even more of a Unix geek than I am :-)) is a graphical front-end. There are a number of alternatives: I personally use the open-source TeXShop (although some may prefer its spinoff iTeXMac).

Note that the default typesetting mode of these applications is pdflatex (since Mac OS X has native PDF support built into its windowing system). This is great for documents that do not involve figures (just text and math), but if you routinely include figures in your papers then you may want to change the default typesetting mode to "TeX+Ghostscript" in "Preferences".

Periodic table programs

If you are a chemist, you would probably like to have a Periodic Table somewhere on your computer desktop. And presumably something more than just a pretty picture: something with actual useful data in it.

If you have 24-hour internet access, WebElements
offers a wealth of information, as does ChemGlobe at the Swiss Federal Polytechnic (ETH Zuerich).

As for offline PToE programs, I own both Periodic Table X and Atomic Mac. The former has a pleasing interface and is customizable, the latter has a wealth of info (radionuclide decay trees, X-ray absorption, you name it).

Neither program has yet been updated yet for element 111 (eka-gold), which was just officially named Roentgenium. Some of the data used are "Caveat Emptor": I pointed out several errors in electron affinity data to the author of Periodic Table X some time ago. They did get fixed (thanks!), but it would be much nicer if either program maintained these data in a human-readable (and human-editable) file, so additions and corrections were possible without having access to the source code.

If your needs are more basic than mine, you can't go very wrong with the freeware Smell-O-Mints.

Utilities of the week: SlimBatteryMonitor, RCDefaultApp, PDF Browser Plugin

SlimBatteryMonitor offers Powerbook and iBook users a replacement for the battery menu icon. It has three different customizable display states: (1) running on battery; (2) running on AC, charging; and (3) running on AC, fully charged. For example, you can have the icon disappear altogether in state (3), be shown estimated time to fully charged in state (2), and time remaining in state (1). You can be shown numbers, or a graphical display on a battery icon: unlike the OS X built-in indicator, the battery icons can be turned vertical, so they occupy as little space in the menu bar as possible.

Desktop Mac users with certain UPSes (uninterruptible power supplies) can supposedly use SlimBatteryMonitor to monitor the UPS. I have not tested this.

The freeware RCDefaultApp adds a "default application for..." panel to System Preferences. This should have been part of OS X in the first place, as the present arrangement for, say, making Firefox your default web browser involves opening Safari (don't ask!) and changing it in the preferences there. But you can also change the default application in which a file with a particular extension opens --- in a much more intuitive way than the standard system interface (which goes via "Get info" in the Finder).

Those of us who need to read scientific papers for a living can barely live without PDF Browser Plugin. It is free for academic and noncommercial use (the first time you browse to a PDF file you will be prompted for your status). This plugin (which uses Quartz's native PDF capability) is only getting better with time. Keyboard navigation, zooming in an out, printing, saving as..., or opening in a choice of external applications (Adobe Reader, Acrobat if it's installed,...). All without leaving your browser. OK, it's not compatible with Microzift Internet Extorter, but who in their right mind would still be using the obsolete and Hebrew-crippled Mac version of that when you can have Firefox or even Safari?