Tuesday, November 20, 2012

Stupid Mac tricks

I have been using a Mac as my primary machine since 2008. From my perspective, Macs offer a fine selection of fully-supported commercial software, excellent OS integration with excellent hardware, and the goodness of a Unix command line--all combined into one product. Below, I briefly outline some Mac-specific knowledge that you may find useful.

Interesting / Useful Commands


There are two Mac specific commands that I'll share as being particularly useful, while also not being readily apparent to a Linux convert:

  • dscacheutil -flushdns -- Flush your DNS cache
  • say -f filename.txt -o filename.mp4 -- Text to Speech into an MP4 audio file
The former simply has an unlikely name, while the latter is remarkably handy for "reading" information away from your computer.

Get your MacBook's battery status from the command line

While I'm sharing, here's how to get your battery's charge level from the command line on OSX Lion. (I can't vouch for Mountain Lion, but it might work there as well.)

file #1 (battery) -- shell script
-----------------------------------------------------
#!/bin/bash
ioreg -l -w0 | grep LegacyBatteryInfo | awk -f ~/bin/battery.awk



file #2 (battery.awk)
-----------------------------------------------------
BEGIN { RS=","
        FS="=" }
/Capacity/ {capacity = $2}
/Current/ {current =  $2}
END { print "Battery charge remaining: " 100*(current/capacity) "%" }



 On my machine, the output looks like this:

jtss-MacBook-Air:bin jts$ ./battery
Battery charge remaining: 67.7165%
jtss-MacBook-Air:bin jts$