Setup
Differences with Traditional UNIX
Misc. Info
Python
Apple's OS X works for most things out of the box. Unfortunately, as it is set up by default, the UNIX parts of the OS are pretty well hidden from the user. This may be fine for desktop users and graphic art/movie people, but it doesn't help people who want the computer to do science, which pretty much requires something like UNIX.
There are lots of pages describing how to set a Mac up for UNIX work, but since I found I needed to use several of them, I am compiling everything I learned (or figured out myself) in one place.
First a little disclaimer: I have a 12 inch G4 powerbook with OS X 10.5 and a MacBook Pro with OS X 10.5. So I only personally test things on these machine. There is no reason why things here shouldn't work on other Macs with OS X, but we all know computers aren't always logical. If something I suggest doesn't work on your machine, please let me know (my email is at the bottom of the page) and I will amend my suggestions accordingly.
Update: I have retired the powerbook and now have a Mac Mini running OS X 10.6 (along with a MacBook Pro running 10.6 at work). Overall, I found very few changes or problems with 10.6 (and most of the changes were in the non-UNIX parts like iCal). So pretty much everything here has now been tested on OS X 10.6 (and some was tested on 10.5 and 10.4)
Generally, I am a GNU/Linux user, and have been for several years. My desktop at work has Scientific Linux on it and my home desktop has Ubuntu (although I went through Mandrake, Fedora Core, and Gentoo before that). Neither are dual boot. I was not especially happy about getting a computer with a non-Free operating system on it. But, OS X is based on a BSD UNIX (which are free), and I primarily use the same software I use in Linux, so at least I'm not getting stuck with proprietary formats. Apple also produces some really nice hardware (and in the case of the 12 inch powerbook, small and cheap hardware). It is nice using a UNIX that is completely supported on the hardware by the manufacturer. And as a bit of a UNIX geek, it is hard to turn down the chance to play with a new (and in a lot of ways different) UNIX that is modern and updated. There are also a lot of people in astronomy using OS X, so it is nice being able to make sure that codes I use work on commonly used platforms.
Now, in case anyone got through all that, on to hopefully useful stuff.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export MANPATH="/opt/local/share/man:$MANPATH"
bindkey "\e[3~" delete-char
bind '"\e[3~" delete-char'
\033[5~
and make sure the
action is set to "send string to shell". For "page down", set it to
\033[6~
. You can probably fix HOME and END in similar
ways but I don't find that those bother me as much.
alias aquamacs="open -a /Applications/Aquamacs\ Emacs.app/"
(when (boundp `aquamacs-version)
(setq confirm-kill-emacs 'yes-or-no-p)
(lisp-interaction-mode)
)
sudo chmod 1777 /var/mail
to make programs like pine and
mailx happy.
Not everything is configured via text files in /etc. There are
several options, mostly for X, that you set from the command line.
To make focus follow the mouse for X (in the proper X-Windows
fashion), type the following in a terminal:
defaults write com.apple.x11 wm_ffm true
defaults write com.apple.x11 wm_click_through -bool true
To make focus follow the mouse in the Apple Terminal App (not xterm):
defaults write com.apple.Terminal FocusFollowsMouse -string YES
I needed to do this for OS X 10.3. 10.4 has the same option, but
it may have been set by default. I don't specifically remember doing
it, but my terminals behave correctly on my laptop.
In ~/.profile:
#Need to set term properly to log on to solaris machines
export TERM="xterm"
source ~/.bashrc
10.5 or earlier only. This works out of the box on 10.6.
In ~/.bashrc:
if [[ -z $DISPLAY ]]; then
disp_no=($( ps -ax | grep X11.app | grep -v grep | awk '{print $7}' ))
if [[ -n $disp_no ]]; then
export DISPLAY=${disp_no}.0
else
export DISPLAY=:0.0
fi
fi
There are a couple of places where OS X is not like the normal UNIX systems we are used to. These are not terrible, but they can cause lots of problems if you don't know about them and find them the hard way. I discovered most of these while porting ZEUS-MP, the MHD code I work on, to OS X.
1. The default filesystem (HFS+) is not case sensitive. It does preserve the case of filenames, so your names don't get mangled, but you cannot have filename and FILENAME in the same directory because they are the same file to OS X (with the default filesystem).
A common practice in FORTRAN programming is to have source files end with .F and contain C preprocessor directives. After preprocessing, the new files end in .f and are then processed by the FORTRAN compiler. This system fails (very badly) as the original files are overwritten by the pre-processed .f files. For zeusmp, I modified the Makefile so the pre-processed files end in .for (also common in FORTRAN circles) while the original source files still end in .F.
2. There is no -static option for gcc. If you see an error where the linker is not able to find crt0.o, it is probably because you were trying to compile statically. There is some horrible workaround hidden somewhere on Apple's website (which involves replacing some system files with ones from OpenDarwin), but just avoiding the -static option seems to be a better solution.
3. There is no /home directory. Home directories reside in /Users. This doesn't really matter, but if you have any scripts that rely on /home, they will fail. The best thing to do is to use ~username in your scripts instead of /home/username so things stay compatible with other systems.
4. This last problem only comes up if you use a USB flash drive, removable hard drive, NFS share, or any other disk that is accessed by non-OS X machines. Anytime you mount (or maybe access, I haven't experimented too much) a directory, OS X leaves behind two files in that directory: .DS_Store and .localized. They are too small to matter, but they do tend to annoy Windows users since they show up in Explorer. They aren't as bad for UNIX users since they start with a period and so are hidden. But it is very annoying that Apple has their system put pointless (at least to other systems) files all over the place (even on resources that may very well be shared) with no good way to turn it off.
There is at least a partial solution to this (from an Apple tech article). In a terminal type:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
This should prevent the creation of .DS_Store files on remote directories.
Here are a couple of interesting commands that are specific to OS X (and possibly darwin, but I don't know).
To access info from the OSX AddressBook.app from the command line:
sqlite3 -separator ' ' ~/Library/Application\
Support/AddressBook/AddressBook-v22.abcddb "select
e.ZADDRESSNORMALIZED,p.ZFIRSTNAME,p.ZLASTNAME,p.ZORGANIZATION from
ZABCDRECORD as p,ZABCDEMAILADDRESS as e WHERE e.ZOWNER =
p.Z_PK;"
I'm not really sure what to do with that yet. I first saw it in the
context of getting an address book for mutt but since I use pine for
my mail (and keep my address book on an imap server), I would need to
play with that a bunch to get it to work that way. But it is still
pretty cool in principle.
ioreg -l | grep IOBattery
I'm not sure exactly how to interpret the output of that, but it is an
interesting way to get some information about the battery from the
command line. I would be interested if someone has a better way or a
better way to interpret this.
pbcopy
pbpaste
These two commands are for copying and pasting from the clipboard.
I'm still not sure what to do with them, but they seem like a cool
idea.
defaults write com.apple.Safari IncludeDebugMenu 1
Enter this command in a terminal. To undo it, enter the same command
only replace the '1' with a '0'. This enables an interesting debug
menu in Safari. Not sure if it is actually useful though.
Python is a great scripting language. I still love regular expressions and the speed at which I can write script to deal with text in Perl, but for data analysis and plotting, python has become my main language.
Of course, I was thrilled that OS X came with python by default. Unfortunately, it isn't set up in the most useful way. For starters, it lacks GNU readline support compiled in. This is annoying if you want to use python interactively. I really don't understand this choice. Apple certainly is not afraid of the GPL. After all, the whole system is built with gcc. And it comes with emacs!
Also, the default python install lacks any array packages. I tend to use numeric, but don't care too much. If you use macports, this is easy enough to install. Install python (sudo port install python26) along with the array package of your choice. Then install python_select in the same way and run that to make the new version of python your system default (python_select python26).
Now when you use python in scripts and on the command line, you get a nice, up-to-date, and more complete version while the Apple supplied version is still around in case you ever need to test against it.