November 12, 2010

High on GEEKdom, part II

You can tell I really don't want to think about work today. Back in April I discovered a bit of software called GeekTool that could turn your desktop wallpaper into a something more. Well, decided I needed a change and started to redesign my desktop last night. And since I'm so into GEEKdom, I decided on an iPod Touch theme. Here's the result:

The iPod Touch on the desktop is as close to the real thing as I could get. Besides the iPod, I have quotes along the bottom of the screen to help inspire me. Below is a detail of the result:

On a normal iPod Touch, the top of the screen has your wifi strength, time and battery status. I decided this would be a perfect place to display the current song from iTunes. The wallpaper are pictures in a folder, some of famous people like His Holiness the Dalai Lama and Gandhi, but also some other iPhone wallpapers I really like. There is a translucent mask over this that is identical to the wakeup screen on the iPod displaying the time, day and date exactly as it is on the real iPod Touch. But where the slider is at the bottom, I've put the current temperature and weather conditions. And last, on the home button is listed the number of unread emails I have in my inbox. Simple but elegant.

Okay, guess I should get back to work now. [smile]

For those interested here is the code needed to do the above. I found this information all over the internet so I'm unable to give proper credit. Suffice it to say that I'm grateful for their work and I hope my results show what is possible.


Geektool code:
date +%l:%M

Day of the week and date:

Geektool code:
date "+%A, %B %d"

Weather for Temperature and Current Conditions (I have them separated). You can change the location by changing MGXX0003 to any USA zip code.

Geektool code Temp: (for Ulaanbaatar in Celcius)
curl --silent "" | grep -E '(Current Conditions:|C<BR)' | tail -n1 | sed -e 's/<BR \/>//' -e 's/\(.*\), \(.*\) C$/\2˚C/'

Geektool code Current Conditions:
curl --silent "" | grep -E '(Current Conditions:|C<BR)' | tail -n1 | sed -e 's/<BR \/>//' -e 's/,.*//'

Current song playing on iTunes: This will work with both songs playing on your Mac but also display song titles from streaming internet radio. I put all of the scripts in a 'Scripts' folder in my Documents folder. Your file path will be different!

Geektool code:
osascript /Users/Jim/Documents/Scripts/iTunes3.scpt

Applescript code for iTunes3.scpt

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"
set playerstate to (get player state)
end try
if playerstate = paused then
set trackPaused to " (paused)"
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 trackPaused & "" & theStream
set artistName to the artist of trackID
set totalData to artistName & trackPaused & " - " & trackName
end if
return totalData
end tell

Display Quotes: I have a text file called quotes.txt that lists quotes, one to a line.

GeekTool code:
osascript /Users/Jim/Documents/Scripts/quotes.scpt | fold -sw900

Applescript code for quotes.scpt

set newline to ASCII character 10
set quoteFile to "untitled:Users:Jim:Documents:Scripts:quotes.txt" as alias
open for access quoteFile
set quoteList to every paragraph of (read quoteFile)
set list_count to the count of quoteList
set pick to random number from 1 to list_count
set finalText to item pick of quoteList as string
close access quoteFile

Unread email: If there are no unread emails then nothing is displayed.

Geektool code:
osascript /Users/Jim/Documents/Scripts/email.scpt

Applescript code for email.scpt:

set newline to ASCII character 10
set finalText to ""
tell application "Mail"
set theMessages to (messages of inbox whose read status is false)
repeat with i from 1 to number of items in theMessages
set thisMessage to item i of theMessages
set finalText to i
end repeat
end tell