Archive for July, 2007

HINT: A (possibly) dangerous way of dealing with messed up Mail.app behavior

MacOS X No Comments »

I like Apple’s Mail.app for reading email. It doesn’t drag down as much as Microsoft Entourage, which uses one monolithic file to store all your email. I say monolithic because when I was last using it, it was over 1 Gigabyte in size (yes, I get a lot of email). With that said, there is an issue that comes up occasionally, and that is that the database Mail.app uses to track email’s status can get corrupted (especially after a crash of Mail.app). Some of the symptoms I have seen:

  1. Typically the start of the problems involve Mail.app misreporting the number of unreads in certain mail directories.
  2. Mail.app looses track of emails I know I have received.
  3. Clicking on an email pulls up a message about that email no longer being available or somesuch nonsense.
  4. In some cases, Mail.app starts crashing much more often. This is what actually caused me to start looking at the Console logs and notice that Mail.app was throwing errors about mailboxes with “negative” numbers of emails within them.

I have found in these situations, I can fix the problems by doing the following in order to rebuild the database.

  1. WARNING: This solution involves deleting files and could leave your email totally destroyed and you without a way to recover. You should darn well BACKUP the “~/Library/Mail” folder before proceeding [you do make backups regularly, don't you?].
  2. I first make screen capture images of my “Unread Messages” and “Flagged Messages” smart folders in Mail.app. Rebuilding the database seems to find messages that were not marked as unread and properly labels them unread. So these snapshots provide an easy way to record what I actually thought was unread. If you don’t have those smart folder built, I suggest building them… smart folders are actually a slick feature.
  3. I then quit Mail.app and move the “~/Library/Envelope Index” file to the desktop.
  4. I relaunch Mail.app, this will prompt Mail.app to “Reimport the email”. This is the process by which it appears to rebuild its database.
  5. Several minutes later, when it is done, I look at my “Unread Messages” and “Flagged Messages” smart folders and “read” or “unflag” any messages that I had previously marked as read and/or flagged.
    • I have noticed that often there will be duplicate copies of the emails left over at this stage. I suspect that when email was moved from my “Inbox” to the folder, the copy in the Inbox didn’t get deleted properly, so it gets recovered in the database rebuild. I have not confirmed this, but it does seem to happen a lot.
  6. Once you are convinced everything is OK, delete the “Envelope Index” file you placed on your desktop.

And that’s it. You mileage may vary, so don’t blame me if this explodes in your face.

AppleCare phone number

Musings 1 Comment »

I have AppleCare on all my Macs. I used to think it was overkill to have a three year warranty, but since getting it on my intel iMac which summarily ate its own motherboard, I have come to realize its a bargain to get the fast access to Apple’s support. I have since used it with a misbehaving iPod, a blown power supply on a MacBook Pro, and to get replacement boot disks for my iMac.

My only complaint about AppleCare is that Apple doesn’t make the phone number terribly clear on their website, so I am noting it here where I can find it. The AppleCare Support number is
1-800-275-2273
and they are open 6am to 6pm Pacific time.

HINT: Fast and loose f77 compilation on MacOS with g77

MacOS X, Programming 1 Comment »
One of the problems I had getting the hectospec IRAF scripts installed was that they used f77 to compile some code. My first thought was to just substitute g77 in the proper places in the hectospec scripts using the g77 binary I downloaded from the High Performance Computing on the Mac website. However, it turns out that g77 is stricter in its interpretation of logical statements than f77 … and so the old hectospec code failed to compile. A proper way to compile this old code is to use the -fugly-logint flag for g77, but that was a pain for so many IRAF scripts. Thus I created the following perl script to allow ancient f77 code to compile properly with g77 on the Mac. I just saved this script to /usr/local/bin and made it executable. Now my old IRAF scripts compile just fine on my new shiny Mac.
#!/usr/bin/env perl
# This script allows the compilation of legacy f77 code with g77 by tossing
# the g77 compiler a -fugly-logint flag to tell it to allow legacy logic
# statements instead of the proper EQV version.

# Initialize
$command = "g77 -fugly-logint ";
for ($i=0; $i<=$#ARGV; $i++)
{
 $arg = $ARGV[$i];
 $command .= " $arg";
}
`$command`;
exit;

Annoyance: Xterm Tektronix emulation broken on MacOS

Astronomical Software, MacOS X, MacOS X Annoyances, MacPorts, X11 No Comments »

Another piece of a fundamental *nix installation that is broken in MacOS X Tiger is xterm. Specifically, the Tektronix 4014 emulation in xterm on the Mac generates ‘empty boxes’ instead of actual characters for text as shown below:

Xterm Broken Display

I found that this problem had been reported on Apple’s X11-users mailing list here, but no solution had been determined. I spent a bit of time looking for “missing” fonts as suggested in the posting, then decided this had to be a problem with the xterm executable and tried my previous solution of installing the program from MacPorts via

sudo port install xterm

Since that doesn’t over-ride the default xterm, I then over-rode the default installed xterm using
sudo mv /usr/X11R6/bin/xterm /usr/X11R6/bin/xterm.disabled
sudo ln -s /opt/local/bin/xterm /usr/X11R6/bin/xterm

Now Tektronix emulation works and I get a screen like the one below:

Fixed Tektronix display on xterm

Annoyance: ksh doesn’t work on MacOS X Tiger

Command Line Tricks, MacOS X, MacOS X Annoyances, MacPorts No Comments »

After several days of trying to get the Hectospec folk’s data reduction packages working on my Mac, I realized one of the major problems was that ksh on the Macintosh had a major problem. Normally, in ksh (korn shell), you can set up a loop to read through a list of objects via a read command within a while..do loop. For example, to echo a list of files your ksh script could contain

#!/bin/ksh
ls -1 . | while read fname; do
  echo $fname
done

where the read filename bit reads a line from the piped input and assigns the first block of text (before a space) to the variable fname. Try this script on MacOS X and it produces no output. “read” fails. This has been documented elsewhere at least twice that I have been able to find with Google, here and here. So clearly, there is a serious bug in the installed version of ksh on MacOS X. I fixed it by updating my ksh using MacPorts, a simple
sudo port install ksh93

followed by changes in the Hectospec scripts to point to/opt/local/bin/ksh instead of /bin/ksh and I was done.

HINT: Maple from the Command Line

Astronomical Software, Command Line Tricks, MacOS X, SciSoft OSX No Comments »

Maple is a nice symbolic mathematics pages from the Canadians at Maplesoft. Our school as a site license which is an awesome deal as students can buy personal copies for much less than the price of a typical textbook. As such, our students can be expected to use the software for their classes. One of the really slick bits on the Mac is you can run Maple from the command line (useful when I need to compute an integral quickly).

I am running Maple 11, so I just placed the following alias in my ~/.tcshrc file (I run tcsh by default because I am old school and dislike bash):

alias maple "/Library/Frameworks/Maple.framework/Versions/11/bin/maple"

If you are running the PPC version of SciSoft, it messes around with some environmental variables, breaking this trick, you can instead use
alias maple "unsetenv DYLD_FALLBACK_LIBRARY_PATH; /Library/Frameworks/Maple.framework/Versions/11/bin/maple; setenv DYLD_FALLBACK_LIBRARY_PATH /scisoft/lib"

If you are using Maple 10, substitute a “10″ where you see an “11″ above.

HINT: Getting AASTeX Installed on a Mac for all users.

Astronomical Software, Command Line Tricks, LaTeX, MacOS X, MacPorts No Comments »

NOTE: I will assume you have installed teTeX (a modern LaTeX package) in one of a variety of ways. Personally I recommend either Fink or MacPorts. However you can get a lot more information about this by visiting the “Getting Started” page at the Mac TeX website.

AASTeX is used to help typeset publications for all the major astronomical journals (at least in the US). You have two fundamental options for installing AASTeX on the Mac:

  1. Single User Install: The easiest way is to download AASTeX (the version for LaTeX 2e) from http://www.journals.uchicago.edu/AAS/AASTeX/ and then just copy the aastex.cls file to whatever directory contains your latex source code for your paper. It should work just fine if you do that.
  2. Global Install: If you want to make the AASTeX class file available to all your Mac users, you need to install it globally where the laTeX installation keeps its latex libraries. The easiest way to do this is to first determine where teTeX keeps its laTeX libraries (referred to as TEXMFMAIN). One simple way to do this is to type the following from the command line
    texconfig conf | grep TEXMFMAIN

    Once you have found that directory, edit the Makefile that comes with AASTeX so that INSTALLDIR equals that directory and fire off a
    sudo make install

    Once you have installed AASTeX, run
    sudo texconfig rehash

    And you should be set.

P.S. - Most teTeX installs come set to European paper sizes. If you want US Letter size, just run the configuration program and set US Letter size pages as the default using:

sudo texconfig

Its text menu driven and pretty straight forward.

HINT: Sportlight indexing for Perl, PHP, Ruby, and Fortran Coders

Command Line Tricks, MacOS X No Comments »

This hint is my writeup based on a similar hint at MacOS X Hints for Making Spotlight index PHP files.

I write a lot of perl code using BBEdit, and wanted Spotlight to index my perl files. To do this, a simple modification of the the SourceCode.mdimporter is needed. First find the type (according to
Spotlight) of the files you want indexed, as PerlFile.pl using this command (via the Terminal):

mdimport -n -d1 PerlFile.pl

which outputs something like:
Import 'PerlFile.pl' type 'public.perl-script' no mdimporter

Now take that file type (public.perl-script) and add it to the Info.plist file located at /Library/Spotlight/SourceCode.mdimporter/Contents/Info.plist (If you can’t find this file, you likely installed Apple’s MacOS X Developer Tools yet). Add it in the array for LSItemContentTypes.

I added:

<string>public.perl-scrip</string>t<string>
public.php-script</string><string>
public.python-script</string><string>
public.ruby-script</string><string>
public.fortran-source</string>

Now you can index your source code files in one of three ways:

  1. Go to a Terminal prompt and type:
    mdimport -r /Library/Spotlight/SourceCode.mdimporter

    to process all your source code files and import them into Spotlight’s database.
  2. Go to the Terminal and trigger the re-importation of the directory containing your source code using
    mdimport /PathToFiles/ToImport
  3. Go crazy and re-import everything on your drive using
    sudo mdimport /

To see what is going on, add the -d1 switch to the mdimport command.

First Post

Command Line Tricks, MacOS X, Musings No Comments »

This is my web blog which I will be using mostly to note things of interest to me. Its not necessarily meant for public consumption and will contain such exciting topics as

  • The installation of software of interest to astronomers on MacOS X machines (I’ve had experience getting AIPS, IRAF and Hectospec’s packages to run under MacOS).
  • Bugs in the MacOS operating system that need to be crushed in order to run some astronomical software on the Mac.
  • Notes on neat command line tricks I discover.
  • Musings on other topics such as teaching or academia.

Don’t expect to see anything too daring yet, I don’t have tenure.