Some notes about setting up OS X to my liking.
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.
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.
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.
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:
Apple's keyboard layout specification.
Place the new keyboard layout in ~/Library/Keyboard Layouts/
.
There's a free program called Ukelele that might help define the layout instead of trying to write that pesky XML.
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.
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
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!
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)
.
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.
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. OK, there's a non-graphical Emacs 22 in base, but I need the real thing.
If you want Emacs from Homebrew linked with gnutls you add
--with-gnutls
.
It's not possible to build Emacs from Homebrew with libxml. If you
want to do that it seems the pkg-config
config file for libxml2 is
missing from OS X. Using libxml2 from Homebrew and compiling your
Emacs against that works.
To run the right version of emacsclient after installing your own Emacs, use this path:
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -t
If you for some reason want a second Emacs process running, just starting a new /Applications/Emacs.app/Contents/MacOS/Emacs is not the way to do it. This creates another process, alright, but things like cut and paste won't work. Instead, use:
% open -n -a /Applications/Emacs.app
You can make an AppleScript of it with the AppleScript Editor and use:
do shell script "open -n -a /Applications/Emacs.app"
if you want something to click on.
A really nice terminal emulator replacement instead of OS X's own.
Works wonders together with tmux -CC
.
Andreas Jonsson et al at Romab has written a sandbox environment for Firefox on OS X. On FreeBSD I usually run Firefox as another user, sort of a sandbox lite, but this is the real thing.
Check under
/Applications/IronFox.app/Contents/Resources/
and read README
and design.txt
for more. A configuration file is
available as IronFox.config
.
Note that there's some more sandbox profiles, as provided by Apple,
under /usr/share/sandbox
.
Essential support for PGP signing and encryption. Integrates well with other tools.
EMMS, Emacs Multimedia System, an Emacs frontend to several different media players.
Given the company I keep I guess I should be running XMMS2 instead, but I haven't tried to build it under OS X yet.
Install mpg321
, flac123
and libtag
from Homebrew.
Clone latest version of EMMS from git.
Copy the emms-print-metadata program
(that uses libtag to be able
to edit music metadata) to my bin
directory.
; Emacs Multimedia System (EMMS)
(add-to-list 'load-path "~/hacks/emms/lisp")
(require 'emms-setup)
(emms-standard)
(require 'emms-tag-editor)
(require 'emms-info)
; Use only libtag for tagging.
(require 'emms-info-libtag)
(setq emms-info-functions '(emms-info-libtag))
(setq emms-info-libtag-program-name "/Users/mc/bin/emms-print-metadata")
(emms-default-players)
(setq emms-source-file-default-directory "~/Music/")
; Play FLAC with flac123.
(define-emms-simple-player flac123 '(file)
"\\.flac$" "/usr/local/bin/flac123")
(add-to-list 'emms-player-list emms-player-flac123)
; Add music file or directory to EMMS playlist on ! in dired.
(define-key dired-mode-map "!" 'emms-add-dired)
Note well: Tag information won't work if you have spaces in file names.
If you really need to change large amount of files and directories,
like I did, consider using the Perl rename
script from Homebrew
and then do:
% find . -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
over your music collection.
Also, note that there's a command-line audio player distributed with
OS X! /usr/bin/afplay
is quite usable from scripts. I use it to
play a sound bite (a quiet ”Hrmph!” I recorded with QuickTime) from
Emacs when my Pomodoro state changes.
Installed with Homebrew. Works with the iTerm2 magic to attach the
terminal emulator to an existing tmux session, tmux -CC
. I mostly
use tmux on remote servers, though.
sshfs – to mount remote directories over SSH's SFTP
Installs fine from Homebrew. Also needs the kernel extension
osxfuse
. Installs automatically by Homebrew but needs handholding
to complete the installation. Read output carefully.
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.
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 is a front end to OpenVPN.
OS X supports IPsec but only IKEv1 (with racoon).
To get IKEv2 support, use Openiked.
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.
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.
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:
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 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.
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.
Multimedia keys (play, pause, fast forward, et cetera)
This little daemon is using them to start iTunes if the keys are pressed:
/System/Library/CoreServices/rcd.app/Contents/MacOS/rcd
but it doesn't seem to run by default. Started by whom?
Last updated: <2016-05-31 09:39:16 CEST>