Miscellaneous OS X tips and tricks

Richard Feynman posthumously advertising a
corporate behemoth Richard Feynman posthumously advertising a corporate behemoth. Good times.

These will be particularly useful if you’re a technical user with experience of the command line or academic software on other Unix systems (e.g. Linux) or Windows. OS X is Unix, but in typical Apple style, things are slightly different. From the point-of-view of the end-user, these differences are generally for the better and you will save time in the long run if you adopt a Mac-like way of working rather than trying to emulate Windows or Linux on your new machine.

0. Using the command line

You have two options. Apple’s Terminal application (which can be found in /Applications/Utilities, but should be dragged to your Dock if you use it regularly) or xterm. Terminal has tabs and other bells-and-whistles on which I’ve come to depend and is easier to configure.

If you use xterm (which you will have to do if you use IDL) then you may want to create and edit a ~/.Xdefaults file to enable some useful features and change font sizes and colours. After making changes run xrdb -merge ~/.Xdefaults or restart X11 to import them. The relevant bit from my ~/.Xdefaults is here. Among other things, I enable the scrollbar (which is off by default!) and change the colours to white on grey.

1. Getting from the Terminal to the GUI: the open command

The open command, which you should run from the Apple terminal (Terminal.app) or an X11 terminal (such as xterm) does exactly what double-clicking on the file would do if you did it in a GUI. In most cases, this means it opens the file in the default application. For example, all of these things can be done in the GUI, but you may find it quicker to stay in Terminal (and of course you can script them):

2. Getting from the GUI to the Terminal: drag-and-drop

If you drag a file or directory from Finder onto your Terminal window then OS X automatically pastes the full path at the insertion point. This is useful if you have found a file in Finder which you want to refer to on the command line. (I use it for drag-and-drop attachments in the mutt email client.)

3. The proxy icon

If you’re using a GUI application which views documents (e.g. TextEdit, Preview for PDFs) then there should be a small icon next to the name of the file at the top of the window. This icon is a “proxy” for the file in the Finder and behaves almost identically to the file itself. You can drag it to the Terminal to get its full path or to another Application to open it with an alternative editor or viewer. The one difference is that if you drag it off the menu bar and onto the Desktop or elsewhere in your directories then you create an alias to that file (the same as a shortcut on Windows and similar to a symbolic link on Linux).

I find this feature particularly useful if I’m looking at a PDF using the preview window in TeXShop but want to view it in a real PDF viewer such as Preview. I just drag the proxy icon from TeXShop onto the Preview icon which I keep in my Dock.

4. Using TeXShop with emacs/vi/your favourite editor

TeXShop is a GUI editor for TeX files which also runs LaTeX and friends for you to typeset the document, generating a PDF. Its built-in text editor is fine, but if you prefer another editor then you can use that in combination with TeXShop while retaining the features which allow you to build and preview the PDF easily.

Open a .tex file in your favourite editor. Open TeXShop and choose Open for Preview from the file menu. Choose the same .tex file you opened in your editor. TeXShop will compile the file and open the PDF if it doesn’t already exist. You can then Cmd-Tab between the editor and TeXShop, making changes in your editor then using the Cmd-T shortcut in TeXShop to typeset the file.

If you would like to make this behaviour the default in TeXShop then tick the “Configure for External Editor” option in its Preferences.

5. Turning the Caps Lock key into a Control key

If you prefer the rarely-used Caps-Lock key to map to something more useful such as Control then you can configure this in System Preferences under Keyboard and Mouse. Choose the Keyboard tab then Modifier Keys. If you are an emacs user then your carpal tunnels will thank you for this change.

6. Make the Finder show the full path at the top of each window

See here.

NEW 7. Getting rid of the error message “XPA unable to verify hostname, setting XPA_METHOD to LOCAL” when running DS9 without a network connection (or on DHCP)

You may see the following error message if running DS9 without a static internet connection:

DS9 error
DS9 error

Unless you’re using XPA then this error can safely be ignored. It is, however, annoying. There are three ways to supress it. I don’t use XPA, so I’m not sure how these interact with XPA, but they do at least get rid of the error message.

  1. edit /etc/hosts to add the line

    127.0.0.1 bembo
    

    where you should replace bembo with your own hostname. You will need to be root to edit this file.

  2. launch ds9 from the command line like this:

    ds9 -xpa local
    

    (The ds9 binary lives in /Applications/SAO Image DS9.app/Contents/MacOS, which you may want to add to your path or alias.)

  3. set the shell environment variable XPA_LOCAL to local. E.g. in bash add

    export XPA_METHOD=local
    

    to ~/.bashrc. This will work if you launch DS9 from the command line, which picks up shell environment variables. If you launch it from the GUI (which you may occasionally do, now it is no longer 1983), then you’ll need to play with ~/.MacOSX/environment.plist so that the GUI knows about the environment variable.