From Linux to Mac OS X…

Digital VT 100 Terminal ⓒ Alex Dawson – Creative Commons

Lately there have been a few people with Linux backgrounds trying out OS X, so I realized I tended to always give the same tricks and explanations, so I might as well factor them out here. The first thing I would recommend Linux users is to take a deep breath: Mac OS X is a form of Unix, but it is not Linux. It is closer to BSD or even Solaris. Some things are different, get over it. Some things are more difficult or impossible some are easier and some hacks are not needed, like the hacking around needed to have an ssh-agent running.

You will probably want to launch the terminal and get back to a command line interface, the terminal is, from the root disk Applications ⇒ Utilities ⇒ Terminal. By default OS X comes with a reasonable set of BSD command-line tools, but there is a good chance that your favorite tool is not present, to get it, you will need to do two things: install the developer tools and the darwin port package manager. The developer tools are an optional install on the installation DVD provided by Apple. You can also download them from the Apple web-site, you just need to register. Once the darwin-ports is installed you can go forward the Unix way: man port.

You can install most open-source tools. OS X has an X11 server installed, but it is only started on demand, this is why the DISPLAY variable contains a weird looking socket. The socket connects to launchd that will start the server on the first connection.

While it is possible to install familiar tools, there are a few Mac OS X only command-line tools that are worth considering:

open
This is probably the most handy Mac OS X command-line tool, it basically opens documents and launches GUI applications. You can use it whenever you want to emulate a click on a Finder Icon (the file-system explorer). So if you want to open the current directory open .. The open command also understands URL.
pbcopy, pbpaste
Those two command put the content of stdin into the clipboard and dump the content of it to stdout. Basically they have the same functionality than xclip.
system_profiler
Dumps the system profile, this is useful to have a view of what hardware the operating system has detected.
mdfind, mdls
Those commands give access to the Spotlight meta-data. They are useful for searching for files and inspecting their meta-data respectively.
hdiutil, diskutil
Those are the tools to manipulate disk images and actual disks. They expose the functionality of the GUI tool Disk Utility.
defaults
Well behaved Mac OS X applications store their preferences in standard property files. The files are in ~/Library/Preferences, but you can just manipulate them using the defaults command.
say
Outputs the content of stdin to the speech synthesizer. Useful for long running scripts.
osascript
This command lets you execute Applescript commands from the command line. This means that you can control GUI programs like Word or Photoshop from the a shell script. The langage can be quite complex, but you can do quite neat things. For instance this small script makes an application quit cleanly.

#!/bin/tcsh
set osa = 'Tell Application "'$1'" to Quit'
osascript -e "$osa"

All those commands have man pages (and none of this info non-sense). The Mac OS X hints web site is also a good source of information on ways to hack the system. One trick I used regularly is this script to create bash aliases for all GUI applications.

3 thoughts on “From Linux to Mac OS X…”

  1. Personally I think the default Terminal application isn’t that good (it doesn’t support mouse reporting and doesn’t allow you to remap the apple keys, for instance). Xterm is still the most customizable, compatible and feature-rich terminal that I know of. Cut and Paste between Xterm and other applications are a bit cumbersome and error-prone, though.

  2. Well, the deep breath I had to take was not about missing tools, in fact, but about **where the damn are the applications**.

    Paths are not the same, and the single reflex to check in Application if something exists was not an immediate one.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: