Reply
   
 Learning to love GeekTool - A primer (Part 2) 
 
 
  #1 (permalink)  
Old 20-09-2008, 07:07 PM
Member

Group: Regulars
Location: Neuchatel, Switzerland


Learning to love GeekTool - A primer (Part 2)

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.
Click the image to open in full size.

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:
Click the image to open in full size.

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:
Click the image to open in full size.

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:
Click the image to open in full size.

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:
Click the image to open in full size.

and this for music library tracks:
Click the image to open in full size.


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.
TigersharkBAS is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #2 (permalink)  
Old 21-09-2008, 08:43 PM
Regular

Group: Regulars
Location: Brisbane


Awesome! Thanks

Unfortunately the iTunes script doesn't seem to work very well for me. Well, it doesn't work at all! iTunes 8.

Nothing is displayed. I've checked all script locations etc.
Apoptosis is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #3 (permalink)  
Old 21-09-2008, 08:44 PM
Regular

Group: Regulars
Location: Hobart, TAS


Nice work once again, TigersharkBAS.
bennyling is online now
Profile CardPM
Go to the top of the page
Reply With Quote
  #4 (permalink)  
Old 21-09-2008, 08:57 PM
Regular

Group: Regulars
Location: Brisbane


Bah, got it to work!

I created the script in text edit and gave it the extension .scpt

I then tried again using script editor and it worked fine...
Apoptosis is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #5 (permalink)  
Old 21-09-2008, 09:00 PM
Regular

Group: Regulars
Location: Brisbane, QLD
Blog Entries: 1


Ahhh this reminds me the trouble I had getting conky to work on Ubuntu!
__________________
MacBook 1.83GHz Core Duo 2GB 120GB HDD
15 GB 3G iPod
Flickr! || Buy My Art!
Successful trades: hMc, chocho, areal, bljpoad, mikeb.aus81, sanjay, thatfilthyspringbok, napes, rpjallan
thebookfreak58 is online now
Profile CardPM
Go to the top of the page
Reply With Quote
  #6 (permalink)  
Old 29-09-2008, 06:47 AM
Regular

Group: Regulars
Location: Berkeley, California USA


Geektool & Fortune

I always thought Geektool & Fortune was kind of fun. Fortune is a MacPorts or Fink install. It works like so:

Last login: Sun Sep 28 14:19:09 on ttys000
[c-76-102-38-166:~] dave% fortune
If God had intended Men to Smoke, He would have put Chimneys in their Heads.
[c-76-102-38-166:~] dave% fortune
There are more old drunkards than old doctors.
[c-76-102-38-166:~] dave% fortune
Theorem: a cat has nine tails.
Proof:
No cat has eight tails. A cat has one tail more than no cat.
Therefore, a cat has nine tails.


Dave
macdave is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #7 (permalink)  
Old 07-10-2008, 06:57 PM
Regular

Group: Regulars
Location: Melbourne


sounds so geeky
__________________
tkilik11
 2 x iMac 24" C2D 2.8 ghz
 iPod Mini 1st Gen 4GB
tkilik11 is online now
Profile CardPM
Go to the top of the page
Reply With Quote
  #8 (permalink)  
Old 12-10-2008, 07:16 AM
Regular

Group: Regulars
Location: Newcastle, NSW


*Is* there an OZ equivalent for the weather thingy? I've looked at BOM and weatherzone but can't find anything that works.
__________________
Hamarana:Redbubble
Apple Stuff: 20" iMac 2.4ghz, eMac G4, iPhone2G.
kyte is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #9 (permalink)  
Old 13-10-2008, 05:26 PM
Member

Group: Member
Location: USA


Unicode??

Hi, thanks for the tips and the scripts. Geektool is great but I'm having some problems with unicode support. I have some scripts which output text in unicode (like the itunes script, i have songs in my library with accented letters) but geektool does not display them properly. Do you know how to correct this? A post in iusethis.com mentions a unicode patch but I couldn't locate it. Thx in advance for any help on this matter.
thegoose is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #10 (permalink)  
Old 20-10-2008, 03:54 PM
Member

Group: Member
Location: Sydney, Australia


GeekTools hasn't been updated for over 2 years. It needs an update before I would use it.
sp0radic is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #11 (permalink)  
Old 20-10-2008, 04:16 PM
Regular

Group: Regulars
Location: Berkeley, California USA


Quote:
Originally Posted by sp0radic View Post
GeekTools hasn't been updated for over 2 years. It needs an update before I would use it.
True, it's not been updated for ages, but is UB and as far as I can tell, works flawlessly on my Mac Pros running 10.5.5. I've been running it over a year straight now on my 8-core and never had a problem with it.

Dave
macdave is offline
Profile CardPM
Go to the top of the page
Reply With Quote
ina
  #12 (permalink)  
Old 27-10-2008, 09:59 PM
Member

Group: Member
Location: Canberra


I can't get the iTunes Info thing to show up. can someone help?
Thanks
ina is offline
Profile CardPM
Go to the top of the page
Reply With Quote
  #13 (permalink)  
Old 03-11-2008, 09:23 AM
Member

Group: Member
Location: Melbourne


Here's a cleaner Applescript with a few extra user-friendly features for displaying the iTunes info.

TigersharkBAS actually asked for it [and a couple of others I use] so he could write it up in this post, but I completely forgot about sending it to him. Here it is anyway.

It only turns on when iTunes is running, and it displays as follows:

Track by Artist on Album
(X stars) 00:00/00:00, X of Y

00:00 and 99:99 are the current position [minutes/seconds] and the full track length. X of Y is the track number in the current playlist.

It will also truncate the top line and replace the end with an ellipsis if it gets too long [I have mine on the left side of my dock, so if it gets too long to fit in the gap, it doesn't go behind the dock]

It works best set up with osascript in GeekTool, set to a one-second refresh. The code below is pretty well commented so you can see what each part does.

Enjoy

Code:
-- A nice applescript for displaying what's playing in iTunes as follows:

-- Song by Artist on Album
-- (# Stars) 00:00/00:00 # of #

-- You can use the script for whatever you want, I'd recommend using Geektool.
-- Applescript by Andrew Harrison ฅสandrew@harrison.org ฅ http://andrew.harrison.org
-- with some parts from Doug's Applescript for iTunes. see below.
-- in Geektool: osascript "/Users/ah/Documents/Documents etc/applescripts/itunes.scpt"

-- First things first, we're going to check if iTunes is running:
tell application "System Events"
	if name of processes contains "iTunes" then
		
		-- Now we know it's running, let's see if it's playing anything:
		tell application "iTunes"
			if player state is playing then
				-- If it's playing, let's get all the info we're going to need:
				-- Get Track Title
				set currtrack to name of current track
				
				-- Get Track Artist
				set currartist to artist of current track
				
				-- Get Track Album
				set curralbum to album of current track
				
				-- Get Track Rating
				set currrate to round (rating of current track) / 20
				
				-- Get Track Position
				set timeVal to player position
				
				-- player position returns number of seconds, so let's make it hours/minutes/seconds.
				-- the seconds -> hh:mm:ss  script is from Doug's Applescripts for iTunes 
				-- (http://dougscripts.com/itunes/scripts/scripts02.php?page=3#replaylastbit) 
				-- I found the script via iPodLounge.
				set numHours to (timeVal div hours)
				set timeVal to timeVal - (numHours * hours)
				set numMinutes to (timeVal div minutes)
				set numSeconds to timeVal - (numMinutes * minutes)
				
				-- build a zero-padded string
				set timeStr to "" as string
				
				-- format the hours. only show if time is 1 hour or more
				-- the if > 0 part was added by me for greater functionality
				if (numHours > 0) then
					if (numHours < 10) then set timeStr to "0"
					set timeStr to (timeStr & numHours)
					set timeStr to (timeStr & ":")
				end if
				
				-- format the minutes
				if (numMinutes < 10) then set timeStr to (timeStr & "0")
				set timeStr to (timeStr & numMinutes)
				
				-- format the seconds
				set timeStr to (timeStr & ":")
				if (numSeconds < 10) then set timeStr to (timeStr & "0")
				set timeStr to (timeStr & numSeconds)
				
				-- thanks Doug!
				
				
				-- Now, we have all the info, so let's get some output happening here
				
				-- First, let's make a string called title info, that looks like
				-- Track by Artist on Album
				set titleinfo to (currtrack & " by " & currartist & " on " & curralbum)
				
				-- We've set up a nice box in Geektool that fits between the
				-- corner of the screen and the edge of the dock. we don't
				-- want the text to wrap to the next line, because that's ugly.
				-- Geek tool can automatically cut it off, but that's also ugly.
				
				-- Instead, let's cut it off at a certain point if it's too long
				-- and replace the last few characters with an ellipsis, which
				-- looks much prettier. 54 is the gap for my dock, you might need
				-- to change it for a higher/lower resolution or if you have more
				-- in your dock than i do. Also, I recommend using a fixed-width
				-- font [i use Monaco] so it's consistent.
				if length of titleinfo > 55 then
					set titleinfo to characters 1 thru 55 of titleinfo & "..." as text
				end if
				
				
				-- next, we'll make a string called trackinfo, which will be
				-- the length, rating and track number of what's playing.
				-- first, get the total time of the track
				set timetotal to time of current track
				
				-- if the total time is less than 5 digits [four plus a colon]
				-- add a 0 to the front so it's the same format as the current time.
				if length of timetotal < 5 then
					set timetotal to "0" & timetotal
				end if
				
				-- then, get the track number in the playlist of whatever's playing
				set tracksleft to index of current track
				
				-- then count the total number of tracks in the playlist
				set trackstotal to count every track in current playlist
				
				-- and output it all like such:
				-- (# stars) 00:00/00:00, # of #
				set timeinfo to "(" & currrate & " stars) " & timeStr & "/" & timetotal & ", " & tracksleft & " of " & trackstotal
				
				
				-- because we have growltunes running, and it pops up with that 
				-- music video thing at the beginning of each song, we're going
				-- to make the output blank for the first 5 seconds of the song
				-- because it would be block by the growl thing anyway
				if player position < 4 then
					set output to ""
				else
					
					
					-- for the rest of the song, though, we want the output to be all the 
					-- stuff we've already organised. it will be formatted like this:
					-- Song by Artist on Album [line break: "/r"]
					-- (# stars) 00:00/00:00, # of #
					-- if we set up geektool to update this once a second, the first counter
					-- will go up each second.
					set output to titleinfo & "
" & timeinfo
				end if
			end if
		end tell
	end if
end tell
To install:

- Fire up Script Editor [found in Applications -> AppleScript] and copy and paste the code above into it.
- Play something in iTunes, then hit the big green Play button in Script Editor to make sure it works [the proper output should show up in the Result field down the bottom].
- If it all works, save it somewhere and note the path. For this example, we'll put it in the Documents folder of your Home Folder, called iTunes.scpt [Users/username/Documents/iTunes.scpt]
- Fire up GeekTool and make a new entry. It should be a Shell script.
- In the Command window, set the refresh to 1 [so the counter works properly] and put the following as the Command:

Code:
osascript "/Users/username/Documents/iTunes.scpt"
[obviously alter that to point to the correct file]

- Customise the colors, fonts, text, position etc. I have mine set to Monaco 9pt White, black shadow with a transparent background, and have put it in the bottom left of the screen.
__________________

Andrew L Harrison
Macbook Pro 2.16 • iPhone 16GB
andrew.harrison.org • @adnrw

Last edited by harrisonx; 03-11-2008 at 09:38 AM. Reason: punctuation etc.
harrisonx is offline
Profile CardPM
Go to the top of the page
Reply With Quote
 
Reply

Thread Tools

 
Similar Threads
 
Thread Thread Starter Forum Replies Last Post
Why do we love mac? 4 reasons? iaakuza Apple General 26 03-10-2007 08:03 AM
Do you love editing too? cosmichobo Projects: Audio, Graphics, Video, HTPC and Programming 15 21-07-2007 08:58 AM
I Love Lamp 2.1, groovier than ever marc iSlayer.com and Bjango Support & Discussion 26 13-07-2007 11:15 AM