Stolen from MC at hack.org

OS X survival guide

Some notes about setting up OS X to my liking.

Introduction

I'm fairly new to the OS X universe. I started using a Macbook Air as my main computer in the summer of 2013, coming from a FreeBSD background. OS X, in my view, is a pretty decent Unix, especially combined with Homebrew. However, it's mostly plumbing for Emacs anyway.

Shell

The default shell is bash but zsh is already installed! Change the login shell with chsh(1).

Some of the installed programs end up in /usr/local/bin. The default PATH doesn't include that, so add that.

Hostname

On a fresh install a Mac sets your hostname to something boring like “Michaels-MacBookAir”. To change it, use:

% sudo scutil --set HostName jsb.hack.org
% sudo scutil --set LocalHostName jsb
% sudo scutil --set ComputerName "Johann Sebastian Bach"

“HostName” is the ordinary hostname. “LocalHostName” is the Bonjour host name. ”ComputerName” is a user friendly version of the above.

Keyboard

First, turn off the unnecessary backlight completely:

and uncheck “Adjust keyboard brightness in low light”. Then lower the brightness with F5 until it's completely switched off.

Then turn Caps Lock into another Control key:

Enable extra keyboard layouts:

and check the layouts you need. If you mark more than one, say “US” and “Swedish Pro” like I do, you can change between layouts with Command-Space. If you mark “Show input menu in menu bar” you can easily see what layout is currently active. Also check “Automatically switch to a document's input source” so your Mac remembers what input source is active in a window.

While you're in the “Language & Text” window you can change to the “Text” tab and uncheck both “Correct spelling automatically” and “Use symbol and text substitution”.

So far I'm using a US keyboard layout for programming and writing in English and Swedish Pro for writing in Swedish. If I ever want to define my own layout here's something to get me started:

Keyboard shortcuts for window operations

As the author of mcwm, I wouldn't want to leave that comfortable environment just because I'm using another window system. Enter Slate. My Slate config tries to mimic mcwm at least a bit.

Display and Desktops

Set an external screen as primary display:

then click and hold on the white bar. Drag to other display.

Easy access to virtual desktops:

Enable Switch to Desktop N. Hit Control-1, Control-2, et cetera, to change desktop.

Turn off desktop icons:

% defaults write com.apple.finder CreateDesktop -bool false
% killall Finder

Turn off the silly Dashboard:

% defaults write com.apple.dashboard mcx-disabled -bool true
% killall Dock

Finder

The Finder creates .DS_Store files whenever it accesses a directory even on remote filesystems. This might not be what you, or your colleagues, want. To turn it off, at least on mounted remote filesystems:

% defaults write com.apple.desktopservices DSDontWriteNetworkStores true

and logout and back in again. The .DS_Store are created as invisible in a Windows share, yet using find to find directories that has changed recently will show the ones which has had such a file created. Annoying!

Whole-disk encryption

Might at least protect against petty thieves. Encrypt sensitive data separetely!

Destroy the FileVault key when hibernating and write RAM to disk when hibernating:

 # pmset -a destroyfvkeyonstandby 1 hibernatemode 25

See pmset(1).

Firewall

Note that the default firewall also filters out ICMP ECHO.

The firewall is based on OpenBSD's pf. Ordinary pfctl(8) is available, so you can write your own pf.conf.

There is also a graphical frontend to pf called IceFloor.

Install necessary programs

Python, Perl, ssh, rsync and a number of other necessary tools are already installed. Proceed to install missing stuff.

There's a nice Ruby based package manager called Homebrew to install third party programs.

You install stuff with brew install foo.

To see if Homebrew has a formula for your favourite program, search with brew search foo.

Other package management systems for OS X are MacPorts and NetBSD's pkgsrc.

Emacs configuration

My ordinary .emacs.el mostly worked.

Gnus and emacs-jabber worked but I sometimes had problems with not being able to authenticate through .authinfo. If I added the IPv6 address of one of the servers explicitly in the file the problems disappeared. Weird.

I had some strange problems with OS X's openssl client. Using gnutls-cli instead worked fine. When I later built an Emacs directly linked with gnutls that worked too.

Set a nice font and colours for all frames:

;;; On OS X
(when (eq system-type 'darwin)
  ;; Monaco for the buffers. Futura for the mode line.
  (set-face-attribute 'default nil :family "Monaco" :height 120)
  (set-face-attribute 'mode-line nil :family "Futura" :height 160)
  ;; Command keys as Meta and Option keys for extra characters.
  (setq mac-command-modifier 'meta)
  (setq mac-option-modifier nil)

  ;; Colour
  (setq default-frame-alist
    (append default-frame-alist
        '((foreground-color . "white")
          (background-color . "black")
          (cursor-color . "#dd9900")))))

The OS X window system works in a very program-oriented way rather than the window-oriented X window managers I'm used to, so I had to define a way of quickly moving to another Emacs frame:

;; Cycle through open frames.
(define-key global-map (kbd "C-.") 'other-frame)

I do the same thing with iTerm windows.

Gnus

My old configuration worked OK. One snag is that the connection to the GPG Tools native GPG Agent dies sometimes. If that happens a

% killall gpg-agent

usually fixes things.

Tunnelblick OpenVPN

Tunnelblick is a front end to OpenVPN.

IPsec

OS X supports IPsec but only IKEv1 (with racoon).

To get IKEv2 support, use Openiked.

Huawei E3276s-150 LTE dongle

I worked over LTE for a few weeks in the summer of 2013 with a Huawei E3276s-150 LTE dongle. It worked under OS X for only a few seconds at a time in NDIS mode. When I changed it to the modem mode it worked fine with PPP.

troff

The built-in troff is GNU groff 1.19.2. A little old and didn't work too good with my Unicode files, but nothing that the built-in iconv couldn't fix. Here's a typical part of a Makefile for my workflow to generate PDFs that works with the built-in OS X tools iconv, groff and pstopdf:

.SUFFIXES: .ms .pdf

.ms.pdf:
        iconv -t ISO-8859-1 $< | groff -ms - | pstopdf -i -o $@

A more modern groff is available through Homebrew and I use that nowadays, but I'll leave this as is if someone needs it.

Apple's pstopdf doesn't crop to the Postscript bounding box properly. I discovered this when using gpresent. Installing Ghostscript and using its ps2pdf helped.

Development tools

Apple distributes a compiler and other goodies, gdb, git et cetera as the Xcode Command line tools. If you try to use anyone of them, for instance git, OS X will ask if you want to download them.

If this doesn't happen go to:

http://connect.apple.com/

Create an Apple ID, if you don't have one already, then go to:

http://developer.apple.com/xcode/

Click “View downloads” and search for “command line tools”. Choose the latest package, download and install. This will give you all the development goodies without the IDE. It uses up about 170 MiBs.

Nota bene: The developer tools are necessary to run Homebrew!

f.lux

f.lux changes the whitebalance on your display according to the sun's position. If the sun's down it changes white to appear more reddish. If it's daytime, white on the screen appears more blue.

This makes it much easier to fall asleep after having stared at your computer all evening.

Xquartz

An X Window System server called X.app used to be bundled in OS X. It's no longer bundled but continues to be developed as Xquartz.

It installs everything under /opt/X11. I needed to change -I/usr/local/include and -L/usr/local/lib to the new prefix and then my window manager, mcwm, compiled cleanly without warnings!

Change the X server to full screen with Command-Option A.

Xquartz uses your ~/.xinitrc. Here's a simple one:

xsetroot -solid grey30 -cursor_name plus -fg white -bg black
xmodmap ~/.xmodmap-mac
xrdb -load ~/.Xresources
~/hacks/checkout/mcwm/mcwm -b 2 -t xterm &
xterm

Unfortunately the xmodmap doesn't seem to work so I have to do it again after starting Xquartz. It looks like this:

! Command is Meta
clear Mod1
clear Mod2
add Mod1 = Meta_L Meta_R

! Left Option is Mod4 - controls mcwm.
clear Mod4
add Mod4 = Alt_L

! Make right option AltGr
keycode 69 = Mode_switch

clear Mod5
add Mod5 = Mode_switch

Xquartz seems to start by itself now and then. I don't know why. I tried doing:

% launchctl unload -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist

which stopped it from doing that. Now I have to start it explicitly before running any X programs.

Xquartz doesn't behave quite like Xorg's usual server. Sometimes it forgets to draw window borders! Annoyingly, it doesn't send a Enter Notify to the window under the pointer when I change workspaces until I move the pointer.

On the other hand, I find that I'm using X less and less.

Still missing


Last updated: <2016-05-31 09:39:16 CEST>