One day my new MacBook Pro 17″ wouldn’t wake up. When I opened the lid machine was running but the Desktop wouldn’t load (just a default blue Desktop background colour) and there was no response from the Mouse or Keyboard. I eventually had to hard reset the Mac.

This annoying issue can apparently be caused a few different ways, but if your Mac is new and has all System Updates applied, chances are that the issue is caused when you close the lid and then move the mac before the contents of RAM are written out. There’s a feature called Safe Sleep, enabled by default, which can preserve and restore the state of a sleeping Mac even when the battery is removed. This sounds great, but the Safe Sleep procedure can take up to 30 seconds, which is too long for me.

How to fix this annoying problem? Here’s how I switched it off:

sudo pmset -a hibernatemode 0
sudo rm /var/vm/sleepimage

…you need to supply the super user password. After making the change, reboot the Mac. The Mac should now Sleep within a couple of seconds. The second line removes the file that Sleep Safe uses to store the contents of RAM. Since you’ve switched off Safe Sleep, the space can be recovered.

Personally I don’t see the need for Safe Sleep on a Mac with a non-removable battery, but be aware that if the machine is asleep and runs out of battery power you wil lose your logged in session! I haven’t tried it, and most OS X apps will deal pretty well with this anyway, but it’s not wise to let this happen…

More details:

Apple pmset Manual
Macworld article on setting sleep modes

Here are a bunch of Mac terminal commands sorted into general categories. I have intentionally omitted long bash scripts and AppleScripts and focussed instead on small useful commands that can be plugged into bigger scripts or used on their own… enjoy!

Terminal & Shell Basics

cmd+n – Open a new Shell in a new window
cmd+t – Open a new Shell in a new tab of the current window
control+d – Logout the Shell in the current tab / window
cmd+d – Split pane. this is not a new shell, just a way of displaying the current Shell.


Restart Mac OS X:

sudo shutdown -r now

Shutdown Mac OS X:

sudo shutdown now

Power Management / Energy Saving

Get overview of current Power Management Settings:

pmset -g

Put display to sleep after 15 minutes of inactivity:

sudo pmset displaysleep 15

Put Computer to sleep after 30 minutes of inactivity:

sudo pmset sleep 30

…Also see my post about hibernate mode and Safe Sleep on the Mac

OS X Look and Feel

Permanently disable Dock icon bouncing

If you don’t like the way Mountain Lion now makes the User ‘Library’ folder invisible, you can disable this.

chflags nohidden ~/Library

…you don’t need to relaunch the Finder.

Disable Dashboard (don’t forget to drag the Dashboard Dock icon off the Dock too):

defaults write mcx-disabled -boolean YES
killall Dock

Enable Dashboard:

defaults write mcx-disabled -boolean NO
killall Dock

Force the Finder to show hidden files (very useful for Web Developers who need to edit .htaccess files, for example):

defaults write AppleShowAllFiles TRUE

Force the Finder to hide hidden files (ie: back to the default setting):

defaults write AppleShowAllFiles FALSE


Ping a host to see whether it’s available:

ping -o

Troubleshoot routing problems to a host using traceroute:


Check whether a host is running an HTTP server (ie: check that a Web Site is available):

curl -I | head -n 1

Automatically enable Internet Sharing at startup

Manage Windows networks (a drop-in for the NET command on Windows). Too many options to list here, so run this for details:

man net

Use dig to discover Domain information:

dig A
dig MX

…and you can also retrieve all available stuff in the DNS Zone for a domain with eg:

dig -t ANY

Who is logged in to your Mac?


What’s my user name? This is really useful for bash scripts etc.


Show routing table:

netstat -r

Show active network connections:

netstat -an

Show network statistics:

netstat -s


List all open files (this will take a few seconds to complete on most Macs):


Restart Bonjour – handy when a Mac ‘disappears’ from the Network:

sudo launchctl unload /System/Library/LaunchDaemons/
sudo launchctl load /System/Library/LaunchDaemons/

Eject a CD… it’s never happened to me but you can eject a stuck cd with the following. Note that it won’t always be ‘disk1’:

diskutil eject disk1

Text Manipulation terminal commands

Sometimes you need to take some text from the clipboard or a file, transform it somehow and then use it. Here are a bunch of mac terminal commands that do text manipulation. I’ve assumed you want to transform text from the clipboard and back again; see the notes at the end of the article for info on how to write to and from files instead.

Count number of lines in the text in the Clipboard:

pbpaste | wc -l

Count number of words in the text in the Clipboard:

pbpaste | wc -w

Sort lines of text in the Clipboard and copy them back to the Clipboard:

pbpaste | sort | pbcopy

Reverse each line of text in the Clipboard (ie: make each line appear backwards) and copy them back to the Clipboard:

pbpaste | rev | pbcopy

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line back to the Clipboard (output is sorted):

pbpaste | sort | uniq | pbcopy

Find duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line (stripping non-duplicates) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -d | pbcopy

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each line (stripping duplicates entirely) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -u | pbcopy

Tidy up HTML in the Clipboard and copy it back to the Clipboard:

pbpaste | tidy | pbcopy

Display the first 5 lines from the Clipboard:

pbpaste | head -n 5

Display the last 5 lines from the Clipboard:

pbpaste | tail -n 5

Convert tabs to spaces for the lines in the Clipboard:

pbpaste | expand | pbcopy

Other useful commands

Password protect your web site! Create a CRYPTed user/password for using in a .htpasswd file. Save the outputted results of A below to a file called .htpasswd in the directory you want to secure. Then save the contents of B to a file called .htaccess in the same folder.


htpasswd -nb username password


AuthType Basic
AuthName "restricted area"
AuthUserFile /path/to/your/site/.htpasswd
require valid-user

Display a history of commands used in the terminal by the current user:


Convert a file to HTML. Support formats are Text, .RTF, .DOC.

textutil -convert html file.extension

Nano is a very easy-to-use text editor for quick changes to text files. It is less powerful than VIM but has the advantage of clearly showing you the common editing commands:

nano [file_to_edit]

…In nano, use ctrl+o to Save and ctrl+x to quit.

Greg shared a way of tidying the terminal window. Essentially this command scrolls down a page, clearing the current view:



Change iTunes link behaviour to point at local iTunes Library instead of iTunes Store:

defaults write invertStoreLinks -bool YES

Change iTunes link behaviour to point at iTunes Store instead of local iTunes Library (ie: back to the default):

defaults write invertStoreLinks -bool NO

Other Mac OS X Terminal Resources

Mac OS X Hacking Tools (old but detailed list for the obsessive only).

Cameron Hayne’s Bash Scripts

Mac OS X Hints

Apple Forums

Note: For commands where I’ve used pbcopy to get the contents of the Clipboard as input, you can use the contents of a file as input instead. Swap pbpaste for:

cat [/path/to/filename]

And to put the results into a file on your desktop, just swap | pbcopy for:

> ~/Desktop/filename.txt


mac terminal command, applescript primer

2016: Updated for El Capitan!

Hey if you find this page useful, check out the 2016 version of my Mac Terminal Commands ebook. It contains all the commands here, plus many new ones, and other useful stuff to do with the OS X Terminal, bash, AppleScript, and more. Get started with Mac scripting now >



MD5 Tool added to site

February 12, 2009 — Leave a comment

Here’s a new MD5 Tool for creating salted hashes of passwords. Just added this because I find it useful and it’s good to share!

Changing directions

February 12, 2009 — Leave a comment

A rare site administration message: I’m moving the focus of this blog away from Undone. Essentially, Undone was a bit of development I did while figuring out some technology, and it now seems like a rather rough and unready piece of software. I’m going to leave Undone running as people are still using it, and you can create new accounts etc if you want too. That said, for serious project management / to do lists etc, I’d recommend something like TaDa lists or installing Redmine or DotProject.

The new focus for will be to cover Mac OS techincal resources, tips, and guides. Sobasically Mac OSX Software: both development tools and general apps like iTunes, Safari etc. These are rough plans, and I’m going to see where it takes me.



DigitalColor Meter is handy for sampling on-screen colour

DigitalColor Meter is handy for sampling on-screen colour

Installed with every Mac, DigitalColor Meter gives you accurate readings of on-screen colours: you can inspect individual pixels, and copy and paste RGB values. When used with Safari or Firefox and a great text editor, it’s a lightweight but powerful tool. Here’s an overview…


  • Find it in /Applications/Utilities/
  • For using with HTML and CSS,  set the colour type to “RGB as Hex Value, 8-bit”
  • Command+Shift+c to copy the current colour as text – perfect for pasting straight into a .css file, alternatively, click and drag from the swatch area to copy the current colour as text (switch this on in preferences first)
  • Command+Shift+h to hold the current colour
  • Set the magnification factor to maximum and the aperture size to minimum for pixel-perfect sampling. Handy for ‘borrowing’ font colours from other sites!
  • Reduce the magnification factor and increase the aperture size for getting an averaged colour – say, when you’re working with gradients or photos
  • When DigitalColor Meter is the active app, you can use the arrow keys to move the aperture in one-pixel increments
  • You can also save the current hovered area as a .tiff file, or copy it to the clipboard. 
  • Set the window to float and keep it in the bottom right of the screen, so it’s always there at a glance. 

One last point: on Tiger at least, if you switch users to a user who has DigitalColor Meter running it will crash. But that’s an annoyance at worst…

Retrospect again

October 31, 2007 — Leave a comment

UPDATE 24 March 2009: Retrospect 8 for Mac OS X has been released!

Just saw this on MacNN: EMC Retrospect 8.0 on chopping block? (ok, it’s months old), so it looks like version 8 definitely isn’t coming to the Mac. Is it just me or does this seem like an opportunity for some hungry Mac developers to build a really good backup system that suits Small Office Networks, has provision for offsite backups like Retrospect does, but sports a swish Cocoa interface and is Universal?

Because basically Time Machine covers local backups but doesn’t serve the same ‘Backup Server’ role that Retrospect Workgroup does…

I know there are some good small backup apps for the Mac out there, but do any backup a network of Macs and provide backup set management?