GeekTool is a fabulously easy way of displaying images from the web and the output of UNIX commands on your Mac’s desktop.

UNIX commands

Within GeekTool drag a “shell” object onto the desktop and paste the UNIX command line into the “command” field. Specify an appropriate refresh interval, in seconds.

Note please there’s a significant difference between a straight quote ' and a back-quote (or back-tick) `.

Time elsewhere

Coworkers in India – how to keep track of their day and night? They’re 12.5 hours ahead of where I lived (in California). So I hardcoded the offset values:

date -j -v+12H -v+30M +"India %a %H:%M"

which returns India Fri 10:36

A better, proper, portable way is to specify the actual timezone in which you’re interested.

TZ=":Asia/Calcutta" date +"India %a %H:%M"

So when you pick up your laptop and travel through a bunch of timezones (and your local time changes) the hardcoded offset doesn’t steer you wrong.

If you display multiple timezones you’ll quickly come to realize that the minutes portion of the time is the same across most timezones, so what I actually use is

TZ=America/Los_Angeles date +"PST %H" ; TZ=America/New_York date +"EST %H" ; TZ=Asia/Dubai date +"Dubai [%a] %H" ; TZ=Asia/Kolkata date +"Kolkata [%a] %H:%M" ; TZ=Asia/Jakarta date +"Jakarta [%a] %H" ; TZ=Asia/Shanghai date +"Chengdu [%a] %H"

which results in

PST 18
EST 21
Dubai [Thu] 06
Kolkata [Thu] 07:32
Jakarta [Thu] 09
Chengdu [Thu] 10

Days since a special date

How to calculate – on one line – the number of days that have passed since a particular date? The stock macOS date can’t do it;

echo \( `/usr/local/bin/gdate +%s --date=today` - `/usr/local/bin/gdate +%s --date=2012-08-26` \) / 86400 | bc

This required a bit more than a stock macOS; get GNU date with brew install coreutils (and if you didn’t know about the homebrew package manager, now’s the perfect time to learn).

macOS swap files

There was a time when macOS did a bad job of cleaning up swap files. For the computer I was using at the time, at about seven swapfiles things started swapping, paging, and hanging, so I kept track of their count and rebooted before I revisited that bad place.

ls -l /var/vm | grep swapfile | wc -l

uptime, natural language style

Want to see how long since your last reboot, your “up time”, in an easy-to-read natural language style, like 2 days 16 hours 38 minutes? The following very long command does the trick:

uptime | cut -d ' ' -f 4- | rev | cut -d ' ' -f 8- | rev | sed -e 's/,$//' -e 's/:/ hours /' -e 's/\([0-9]$\)/\1 minutes/' -e 's/,[ \t]/ /g'

Monthly calendar blocks

cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date "+%e"`; echo "$cal_head"; echo "${cal_tail/${today}/\033[1;32m${today}\033[0m}";

generates a one-month calendar block with the current day highlighted, if your terminal supports that sort of thing.

June 2016
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

To get the next or past month(s), use something like:

cal `date -v +1m "+%m %Y"`

Top CPU usage, as simple as possible, sorted

Under macOS, the command I use to see a one-time list of the top CPU consumers and the percentage each uses, sorted with hungry apps above, is:

ps -racwwwxo "command %cpu" | head -20

Note that on a multi-core computer the percentage can be over 100%. Truncated sample output:

Google Chrome He 119.8
Google Chrome He 97.0
Finder 33.5
Google Chrome 13.9
iTerm2 6.2
Slack 5.6
TextWrangler 5.4

Universal Coordinated Time (UTC)

UTC – Universal Coordinated Time – is the shared abstract time reference that came into being with atomic clocks. Note that it’s not a timezone, like GMT (Greenwich Mean Time), but rather a term referring to mean solar time at the Royal Observatory, Greenwich, England. UTC is really useful when you’ve got people or computers around the world and you want a common time as a reference.

Displaying UTC in 24-hour format:

date -u +"%R"

iCalBuddy formatting

iCalBuddy displays the contents of your Apple Calendar database with a remarkable range of formatting options. The command

/usr/local/bin/icalBuddy -sd -ss " " --includeCals "Calendar" --excludeEventProps "notes,url,location,attendees" -npn --formatOutput --noCalendarNames --propertySeparators "/ » /" --timeFormat "%H:%M" --dateFormat "%A %m/%e" eventsToday+10 | sed -e 's/day 0/day /g'

shows my appointments and times in a most compact, easy-to-read fashion. Actual output is colorized by calendar.

• Demo » 10:00 - 10:30
• Cold Tea » 13:00 - 14:00

Monday 6/13:
• Some Thing » 11:30 - 12:00

Tuesday 6/14:
• Status Updates (stand-up) » 08:00 - 08:30
• Show and Tell » 12:00 - 13:00
• Release Prep » 15:30 - 16:00

Internet Protocol (IP) addresses

Each device connected to the Internet — your laptop, your smartphone — acquire a worldwide unique identifier; your external IP address. Devices connected to a Wi-Fi access point are also a local or internal IP address.

% ifconfig | grep "inet " | grep -v | cut -d\ -f2
IP address
% dig +short

GeekTool and images

Within GeekTool drag an “image” object onto the desktop and paste either a URL that points to an image or selects a local image. Specify an appropriate refresh interval, in seconds, if the URL points to webcam stills. Resizing the window resizes the window within. Cropping not supported.

Leave a Reply

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