By now you should have celebrated your geekness and delved right into GeekTool. It may have even inspired you to experiment more with some basic Unix commands and the Terminal. Congratulations...pocket protectors are being dispatched to you as you read this.
If you are reading this you are thirsty for more geek goodness so sit back and enjoy the part where we talk about a process monitor, calendar, weather display and some ideas for other uses.
Oooo...process monitor thingy...gimme gimme gimme!
To implement the process monitor we need to use another external script called from GeekTool. Similar to how we implemented the IP address and network monitoring.
Create a text file anywhere convenient and call it processinfo.bash
Copy the following code in to the file. Props to Curby who authored this funky script.
Code:
#!/bin/bash
### Curby's GeekTool process listing script (ps+top version)
### by Michael 'Curby' Lee
### v1.00.00, 2007-02-17
### Description
#
# Outputs a list of processes using the most CPU time recently,
# processes having used the most CPU time since they started, and
# processes using the most memory (largest resident memory size).
#
# Compared to geektool-ps and geektool-top, this runs the slowest
# but displays the heftiest programs sorted in three ways and has
# the slimmest output (horizonally).
#
### Suggested use
#
# This script can be executed from the OS X commandline without
# administrative priveleges, but is intended for use with GeekTool
# with a refresh time of 10 seconds. The number of processes
# displayed can be customized below. This script was tested on
# OS X v10.4.8 with GeekTool v2.1.2(112). The script may fail with
# other versions of ps and top.
#
### License
#
# Copyright (C) 2007 Michael Lee
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#-------------------------------------------------------------------------------
# Configuration
#-------------------------------------------------------------------------------
cpu_rows=15
time_rows=15
mem_rows=15
#-------------------------------------------------------------------------------
# Output
#-------------------------------------------------------------------------------
echo "COMMAND PID %CPU"
ps -c -r -ax -o command,pid,pcpu | sed 's/^\(.\{10\}\).\{6\}\(.\{6\}\)..\(.\{4\}\)$/\1\2 \3/' | head -n $(($cpu_rows+1)) | tail -n $cpu_rows
echo
top -l1 -otime -n $time_rows -F -R | tail -n $(($time_rows+1)) | sed 's/\(.\{5\}\) \(.\{10\}\).\{8\}\(.\{8\}\).*/\2 \1 \3/'
echo
ps -c -m -ax -o command,pid,pmem | sed 's/^\(.\{10\}\).\{6\}\(.\{6\}\).\(.\{4\}\)$/\1\2 \3/' | head -n $(($mem_rows+1))
When you have pasted the code, save the file and then use terminal to navigate to the same dir as the file and type chmod 755 processinfo.bash (to make it executable).
Now in GeekTool you need to call the file. Create a new Shell object and type the following (replacing the path info with the path to your file naturally):
Code:
bash /Users/jvl_iMac/bin/processinfo.bash
You should now have a nice process monitor that shows top 10 processes by CPU usage, time, and Mem use.
Take a moment to bow before the geek gods, eat a bag of Doritos, read Slashdot and come back to our next task.
Shiny shiny weather map...GIMME!
OK, this one is not as complex as it appears. This is an example of using GeekTool's Image function. Remember in part 1 we talked about Shell, Image and File objects.
Shell executes commands and scripts, File simply displays the contents of a file and Image (JPG) displays a picture. You can control how often this picture updates and the opacity of it on the desktop.
As I live in Switzerland I was able to source the URL for a weather radar image they publish every 15 mins or so. I typed the URL in the text box, gave a refresh of 120 sec. and set the opacity to around 50%. Try and source a similar image from the Met Bureau and you will have the same thing.
In case you simply want to experiment with this image until to find an Oz equivalent the URL is:
Code:
http://www.nzz.ch/images/niederschlagsradar_1.166.jpg
The result is this:
Real Geeks use ASCII - The Monthly calendar.
The calendar is simple Shell object with the following code:
Code:
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"
The current day has two ## symbols. The following is the result:
Displaying the System Log
Finally, in the center of the screen we have the system log which often shows useful information of why apps crashed, if backups didn't work, what apps are writing information to certain log files, etc.
To display the syslog simply create a Shell object and type in the following:
Code:
syslog -k Time ge -600
Here is a sample of what it will look like:
Displaying iTunes Info
This displays both music library and streaming radio info.
Create a text file called iTunesInfo.scpt and copy the following code into it:
Code:
tell application "System Events"
set powerCheck to ((application processes whose (name is equal to "iTunes")) count)
if powerCheck = 0 then
return ""
end if
end tell
tell application "iTunes"
try
set playerstate to (get player state)
end try
if playerstate = paused then
set trackPaused to " (paused)"
else
set trackPaused to ""
end if
if playerstate = stopped then
return "Stopped"
end if
set trackID to the current track
set trackName to the name of trackID
set theStream to the current stream title as text
if theStream is not "missing value" then
set totalData to "Stream : " & trackName & trackPaused & "
Title : " & theStream
else
set artistName to the artist of trackID
set albumName to the album of trackID
set totalData to "Track : " & trackName & trackPaused & "
Artist : " & artistName & "
Album : " & albumName
end if
return totalData
end tell
To get GeekTool to display it create a Shell object and paste this into it (of course, replacing the path info to the path of your script file):
Code:
osascript /Users/jvl_iMac/bin/iTunesInfo.scpt
The result will look like this for streaming radio:
and this for music library tracks:
Conclusion
I hoped you enjoyed this little GeekTool primer and that is has regenerated your inner Mac geek.
With a little imagination it can be insanely powerful, displaying Web site traffic graphs, displaying info from iTunes, usage stats from your ISP, etc.
There are plenty of sites out there that will offer inspiration. Share your uses or unique applications of GeekTool in this thread.
Fellow geeks...I bid you farewell.