Uncategorized

Mac OS X

After 12 years on Linux, I’m grudgingly switching to Mac OS X. I wasn’t excited about it, but it’s better than I expected. It’s not news any more, but yes, OS X is a usable, pretty skin on top of a real POSIX OS. Darwin is definitely different from Linux, but it’s close enough to feel familiar, and smooths over pretty much all the rough edges you might hit on a Linux distro.

Even so, it’s a big change from what I’m used to. Here are some of the things I’ve done to make it feel comfortable.

Homebrew

One of the first things I missed was APT, the package manager. Apple’s App Store is nice, but it’s aimed at end users, so it’s not so good for installing e.g. GNU utilities or MySQL. A while back I might have used MacPorts (nee Darwin) or Fink, but the new hotness now is Homebrew, which I’m liking a lot.

One note: homebrew formulae that include .app files usually put them in /usr/local/Cellar/[formula]/[version]. You can symlink them directly into Applications from there to install them.

Another note: for .apps to use binaries installed by homebrew in /usr/local/bin, e.g. emacsclient, you need to add that path to the default PATH environment variable for OS X apps with launchctl setenv`. Warning: Homebrew’s instructions. point to this Apple doc, which doesn’t work in Mountain Lion!

Here are some packages I’ve installed so far:

  • autoconf
  • automake
  • colordiff
  • coreutils
  • emacs
  • exif
  • flickcurl
  • fontconfig
  • freetype
  • fuse4x
  • gettext
  • glib
  • gnupg
  • go
  • graphicsmagick
  • imagemagick
  • jpeg
  • libexif
  • libpng
  • libtool
  • libyaml
  • mercurial
  • mpg123
  • mplayer
  • mysql
  • pkg-config
  • pstree
  • rename
  • sshfs
  • wget

Homebrew is great at upgrading, and you can use brew switch to downgrade to an older version, but only if you already have it installed. If you don’t, there’s no an easy way to install it. On the rare occasion that I’ve needed to, I followed this recipe. Executive summary: cd /usr/local, run brew versions PACKAGE, run its git checkout command for the version you want, then just run brew install PACKAGE [OPTIONS] and optionally brew [un]link PACKAGE.

Apache is installed but not started by default; run apachectl -k start to start it. Here’s more on setting up LAMP. One word of warning: don’t start/stop/restart MySQL with sudo /Library/StartupItems/MySQLCOM/MySQLCOM start. That brings it down but refuses to bring it back up, at least on my machine. I have to reboot to get it running again. :(

Window management

One of the most important parts of my Linux setup was my tiling window manager, Ion, which I followed with a brief stint on notion (a fork) after Ion’s author went crazy.

It’s also the part that I haven’t been able to match, at least so far. I’ve found programs with similar ideas, but most of them seem like glorified bags of shortcut keys for pushing windows around. I haven’t found many that actually manage my windows for me. I’m not the only one, either.

Ah well. xnomad, Slate, and Tyler WM seem the closest so far. I’m trying out Slate right now; here are my .slate and .slate.js. We’ll see how it turns out!

(Some of the shortcut bags look pretty good, too: Moom, ShiftIt, Divvy, SizeUp, Spectacle, Optimal Layout, Doublepane, Stay, and others.)

Emacs

I pretty much live inside just two programs: Emacs and Firefox. I was able to migrate my configs for both, which made switching OSes a lot easier.

There are plenty of Emacs packages for OS X. I used Homebrew and ran brew install emacs --cocoa to get Emacs 24.2 with native full screen support backported from 24.3.

I hadn’t used Emacs 24 before this. One of my favorite new features is the built in package manager. Here are the extra packages I’ve installed so far:

Emacs’s GDB integration is great, but it takes a few extra steps to get it working on Mac OS X.

Darwin’s GDB 6.3 seems to work, but doesn’t really. Programs running under it crash randomly where they wouldn’t otherwise. :/ First, get GDB 7.5 via homebrew instead by running brew install gdb. Then, sign gdb to tell the kernel it’s allowed to attach to other processes. Follow these instructions, then run codesign -s gdb-cert /usr/local/Cellar/gdb/7.5.1/bin/gdb (assuming you named your certificate gdb-cert.)

Now run M-x gdb in Emacs and enter /usr/local/bin/gdb -i-mi [BINARY], or M-x gud-gdb and /usr/local/bin/gdb --fullname [BINARY] if you want the old version of GUD, and you’re off!

Sometimes Emacs gets unhappy and complains Wrong type argument: frame-live-p, #<dead frame … whenever I try to kill a buffer. This fixes it: M-: (setq menu-updating-frame nil).

Firefox

I migrated my Firefox profile by brute force: I copied my profile directory directly from ~/.mozilla/firefox/personal/ to ~/Library/Application Support/Firefox/Profiles/personal and updated the fully qualified home directory paths in prefs.js, search.json, extensions.ini.

This mostly worked, but a few things like history didn’t entirely make it. Next time, I might consider a backup and restore utility like FEBE instead.

I also noticed that fonts were grainy on Firefox 19 on my retina display. Evidently this is temporary until Firefox 20, to work around a bug. I followed these instructions to re-enable retina display support by setting gfx.hidpi.enabled to 2 in about:config.

One note: my tweak to stop app tabs from glowing when they have updates didn’t work out of the box. It took a while, but someone on the Apple StackExchange finally led me to the fix. Yay!

Also, another not-Mac-related note: I love Greasemonkey, and I also love the Twitter Keyboard Shortcuts userscript. It makes o open the first link in a tweet, p go to the author’s profile, and more. So useful.

Mac OS X

There are lots of little differences in the OS and its shell. To start, I knew it would ask me to make an Apple Id for use with the App Store and other Apple services, but I didn’t expect it to be quite so aggressive. Even so, I’ve managed to sidestep it so far. I had to create one to download XCode, but I’ve avoided attaching it to the computer itself.

Programs are usually run as .app files, executable archives that include a manifest, binaries, supporting files, icons, etc. They’re usually placed in the /Applications directory. The actual binary(ies) are in XXX.app/Contents/MacOS/.

Outside of the App Store, there are two standard ways to install programs. .dmg files are disk images, not zip files or installer binaries. Double click on them to mount them, drag the application file inside to the Applications folder, then unmount the image and optionally delete it.

.pkg and .mpkg files are package and multipackage installer binaries, respectively. They’ll open with the built in installer program automatically, or you can run it manually: sudo installer -pkg /Volumes/someapp/someapp.mpkg -target /

Power management is pretty solid out of the box, and there’s even a useful command line utility, pmset. There’s no built in way to tell it not to sleep when the lid closes, but there are third party programs like InsomniaT and NoSleep. Power nap looks related but isn’t; it’s proprietary and only wakes up to do Apple-specific things. Incidentally, the keyboard shortcut for sleep is Cmd-Option-Power.

System Preferences is self explanatory; it’s the equivalent of dotfiles in *nix and Control Panel in Windows. I think it’s actually just a pretty frontend to System Information (in Utilities), which is similar to GConf or the Windows Registry. The actual preference data is (sometimes?) stored in .plist files. There used to be a standalone Property List Editor app, but now it’s embedded in XCode. There’s also the defaults(1) command line program.

There’s a cottage industry of system tweaking programs like Onyx and Cocktail, similar to Windows’s venerable Power Toys, that just set preferences that aren’t exposed in the System Preferences UI. There are also plenty of good lists of individual useful settings to change.

I turned on FileVault 2, Apple’s full-disk encryption system, which is evidently much better than version 1. The only disappointing thing is that it requires me to log in with my password after a certain amount of idle time. I tried to disable that, but I needed to turn on automatic login, which FileVault doesn’t allow. I even tried variations on defaults write com.apple.screensaver askForPassword 0, but no luck. Sigh, oh well.

Networking is pretty straightforward, and has its own command line utility, airport.

Keychain integrates with SSH keys automatically, which is pretty damn cool. Sadly it doesn’t also handle GnuPG keys, but I only use mine rarely, so I don’t mind typing the password each time or just using stock gpg-agent.

To set your hostname in the GUI, go to System Preferences, Sharing, Computer Name. To do it from the command line: scutil --set [HostName,LocalHostName,ComputerName]

Run this to always show the full path in Finder windows: defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES.

Sound has a nice feature: it automatically remembers volume for headphone vs speakers separately, which helps you avoid blowing out your eardrums. Nice.

Oddly though, the baseline volume is too loud for a few of my headphones. Other people have the same problem. This StackExchange question offers a number of solutions:

  • Hold Option and Shift while pressing the volume buttons to get smaller increments, or use the Menu Bar icon. Neither of those go as low as I’d like, though.
  • Use the Volume Down button to lower the volume all the way to zero, then press the Mute button to unmute. This goes much lower than even the smallest Option-Shift increment.
  • Use AppleScript: osascript -e "set Volume 0.01". I couldn’t get it to register anything below .01, though, which is the same volume as the unmute trick above.
  • Install a third party equalizer like Hear or limiter like Sound Bunny or Volimiter.

In the end, I went the low tech route and passed -volume 1 to mplayer, my music player of choice.

If you have multiple displays, the Menu Bar is always on the “primary” display. This is inconvenient when you’re working on another display. You can move it, but you need a third party app to duplicate it on all displays. Also see this discussion, among others.

Many *nix-isms work like you’d expect, but not all. .login files are one that didn’t make the cut. To resurrect yours, put it into a shell script, or just chmod +x it and add #!/bin/bash at the top, then add a Login Item for it to your user in System Preferences => Users & Groups.

cron is deprecated on Mac OS X in favor of Apple’s own launchd. I ported my crontab with this tutorial and Apple’s reference doc.

Keyboard and mouse

Thanks to Fitts’ law, I tend to use the keyboard much more than the mouse. Fortunately, OS X has lots of built in keyboard shortcuts, and it’s very configurable out of the box. You can also add shortcuts to third party applications, to a degree, and wonder of wonders, even swap Caps Lock and Control. (Speaking of which, if you do that in System Preferences, remember to do it in each keyboard you use!)

Beyond that, the best thing I’ve found to make OS X more keyboardable is KeyRemap4MacBook. I use it to get Sticky Keys that don’t lock, add Emacs key bindings in text controls, reclaim some of the function keys, make Control-arrow keys navigate by words, make Return act like Control when it’s held down, and emulate my beloved missing Page Up and Page Down keys.

One KeyRemap4MacBook note: if you bind simultaneous key presses, e.g. pressing both down and right arrow keys together to Page Down, try lowering the [Simultaneous Key Presses] Delay Threshold setting in the Key Repeat tab as low as you can, ideally 10ms or so, so that pressing those keys in rapid succession doesn’t accidentally trigger the new binding.

It’s not all kittens and rainbows, though. I sorely miss Windows and Linux’s Shift-F10 shortcut for right click. Evidently there isn’t an equivalent one in OS X. You can use mouse keys and Ctrl-5, but that ties up the rest of keyboard, so it’s not really an option.

Likewise, there’s no built in shortcut for maximizing a window, but you can easily add one on an app by app basis in System Preferences, using the Zoom menu item.

I also dreadfully miss navigating menus with the keyboard. There’s a keyboard shortcut to focus the menu bar, but it doesn’t work in all apps, e.g. Emacs.

Finally, some modal dialog boxes can’t be navigated with the Tab key, even with Full Keyboard Access set to All controls in System Preferences => Keyboard. I think the common thread is that those dialog boxes don’t have a corresponding GUI app running, e.g. Slate. I thought they were utility windows, but they don’t respond to Ctrl-F6 either.

Xcode

I prefer to write code in Emacs and read docs in Firefox, but I’ve been working on iOS apps recently, which Apple only halfheartedly supports outside of its IDE, Xcode. Fortunately, other people have stepped in to fill the void.

Apple’s developer docs for Objective C, Cocoa, Mac OS X, iOS, etc. are stored on your hard drive as HTML – yay! – so they’re easy to read in a browser. Look in ~/Library/Developer/Shared/Documentation/DocSets and point your browser at Contents/Resources/Documents/index.html inside the docset you want to read.

docsetutil (/Applications/Xcode.app/Contents/Developer/usr/bin/docsetutil) also looks handy. It can search an index of all installed docsets, and there’s Emacs integration.

I’m currently trying out Dash, a document viewer that includes a ton of docsets for popular languages, platforms, and frameworks. It looks great so far, and has Emacs integration too.

Miscellaneous

I used Pidgin on Linux. Adium, its OS X counterpart, seems like an ok replacement so far. One obscure feature I liked in Pidgin was the ability to turn off the “Ryan has left the conversation” notifications that it sends when I close chat windows. Happily, it looks like Adium turned these off entirely a while back.

I’m using Menu Meters to get minimal CPU and network activity monitors in the menu bar.

I’m using HoRNDIS for tethering over USB to my Android. I wish it put an icon in the menu bar, but otherwise it’s great.

The built in Python doesn’t read my ~/.python. Not sure why yet.

I have an Android phone, which meant I needed to download Google’s Android File Transfer MTP program to transfer files to it over USB. It works, but has one annoying feature: it automatically starts whenever I plug my phone into my computer. I followed these instructions to disable that. Be sure to kill it in Activity Monitor before removing the login items and renaming the agent app!

Recently, I’ve seen a distnoted process occasionally spin up and chew up 100% CPU (on one core) and a ton of memory, often in the neighborhood of 1.5G or so. The command line is /usr/sbin/distnoted agent, and it’s started by launchd, neither of which help much. Web searches say distnoted manages notification delivery, and lots of other people report the same problem with it, but no single clear fix.

I asked about it on StackExchange, and after some debugging, we determined that it was being started by Spotlight, OS X’s filesystem search feature. I’ve reined in the paths and file types that Spotlight is allowed to index, but that hasn’t fixed it.

…it turns out this is probably an Emacs memory leak that’s fixed in 24.4. Fingers crossed!

Standard

19 thoughts on “Mac OS X

  1. Your use of computers sounds a lot like mine. I went through a similar process a few years ago, and subsequently switched back to Linux. I’m happier with the feeling of freedom and control that I have on Linux, but on the other hand I have spent quite a lot of time tinkering with my kernel config, packages, settings, etc. Of course I did the same when I switched to OS X, like you appear to have done. If I weren’t so obsessive about tinkering, I probably could have skipped most of that and been fine. Functionally, I find Linux and OS X pretty much equivalent for my uses. There are a few things better on one than on the other, most of which you mentioned. I’m happy on Linux now. I’m thinking of getting a Google Chromebook Pixel and installing Ubuntu on it.

  2. I tried, gave up and used Ubuntu instead on a think pad. The first you need to do on a Mac is to install "Unix" as it does not come with the stuff needed in as normal Unix. That's kind of bad sign. Cygwin under window is easier… via Google+

  3. Nelson says:

    Does it seem prettier to you? Give Alfred.app a try some time; it’s a good launcher + general GUI tool.

  4. I’m a layman, but I think Linux is simpler and more stable with parallel processes, and less proprietary so many people can add improvements. Does this shift mean that Apple’s OS is nonetheless better designed? via Facebook

  5. I tried to use a MacBook Pro 5 years ago, for a week, couldn’t figure out a solution for PgUp/PgDown and Caps/Ctrl. That was my primary reason for giving up on the experiment, glad to see that’s easier to do now :-)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>