Geektool: Virtual Desktop Enhancement
I have really grabbed a huge amount of shell scripts in the past two days and I’ll give you here my experience on Geektool (with all my grabbed scripts).
What it’s GeekTool
It’s actually a preference panel and creates a layer over the desktop which can be utilized to place picture, text file and shell script output. Most of the people use the last one (shell script output) to monitor their system like cpu hogger, etc
How to install?
Follow the link here and it gives you excellent screenshot tour
Here’s my screenshot
Click here to see more information of the Screen shot
Categories:
My current scripts (look at the screen shot of my desktop)
Day of week: date +%A
Month: date +%B
Date: date +%d
Time: date +"%I:%M"
Alternatives:
Without the '0' infront of the hours 1-9, use: date +%l:%M
24 hour clock, with seconds: date '+%H:%M:%S'
24 hour clock, without seconds: date '+%H:%M'
AM/PM: date +"%p"
Date:
"date +"%A %d %b" (which results in Monday 12 June)
Time:
"date +"%I:%M %p" (which results in 11:30 pm)
If you want a 24 hour clock (e.g. 03:00 a.m.) then replace %I with %H. If you want to add seconds there, add %S to the mix. Remember to change the refresh rate to every 1 second if you’re adding seconds.
Short: Only shows 3 letters of the day. for example 'Wed' instead of 'Wednesday'?
date +%a
Timezones
Just change the names and GMT value to get the required clock.
TZ=US/Hawaii date +"Hawaii : %I:%M %p %a"
TZ=Etc/UTC-8 date +"Maylasia : %I:%M %p %a"
TZ=Canada/Pacific date +"Vancouver: %I:%M %p %D"
TZ=Africa/Johanessburg date +"Africa: %I:%M %p %D"
TZ=England/GMT date +"London:%l:%M %p on %d %B"
TZ=Germany/GMT-1 date +"Frankfurt:%l:%M %p on %d %B"
TZ=Australia/GMT-11 date +"Melbourne:%l:%M %p on %d %B"
TZ=NewZealand/GMT-13 date +"Wellington:%l:%M %p on %d %B"
TZ=Alaska/GMT9 date +"Anchorage: %I:%M %p - %D"
TZ=NewYork/GMT5 date +"New York: %I:%M %p - %D"
TZ=England/GMT date +"London: %I:%M %p - %D"
TZ=Australia/GMT-10 date +"Sydney: %I:%M %p - %D"
TZ=IST/UTC-5:30 date +"Chennai: %I:%M %p %a"
Last Timemachine backup
save it as timemachine.rb, +x permissions, then configure in geektools as necessary. Can probably get it down to hours if you need it that badly.
#!/usr/bin/env ruby
require 'date'
date =`head /var/db/.TimeMachine.Results.plist | grep date| awk -F'<|>|T|:|Z' {'print $3'}`.chomp.split("-")
gap = (Date.new(Time.now.year,Time.now.month,Time.now.day) - Date.new(date[0].to_i,date[1].to_i,date[2].to_i) )
if gap > 14
puts "you gotta backup. its been #{gap.to_i} days"
else
puts "na, you're cool. its only been #{gap.to_i} days"
end
-----------------------------
Can you make it show hours and days? IE: It has been 4 days and 3 hours since last?
Done
----
#!/usr/bin/env ruby
# require 'date'
public
def to_seconds; self; end
def to_minutes; self/60.0; end
def to_hours; self/(60*60.0); end
def to_days; self/(60*60*24.0); end
def to_weeks; self/(60*60*24*7.0); end
def days; self * 60 * 60 * 24.0; end
date =`head /var/db/.TimeMachine.Results.plist | grep date| awk -F'<|>|T|:|Z' {'print $3 "-" $4'}`.chomp.split("-")
gap = (Time.local(Time.now.year,Time.now.month,Time.now.day,Time.now.hour) - Time.local(date[0].to_i,date[1].to_i,date[2].to_i,date[3].to_i) )
days = gap.to_days.to_i
hours = (gap - days.days).to_hours
if days > 14
puts "you gotta backup. its been #{days} days and #{hours} hours"
else
puts "na, you're cool. its only been #{days} days and #{hours} hours"
end
-----------------------------
Go to yahoo weather in web browser and search for your city. Now you have to search for some code in address bar (URL), it looks like this "GMXX0154". Copy the code and replace "GMXX0154" it in the following script
Current weather
curl --silent "http://weather.yahooapis.com/forecastrss?p=GMXX0154&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
Or
curl --silent "http://weather.yahooapis.com/forecastrss?p=GMXX0154&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//'
Forecast
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=GMXX0154&u=c" | grep -E '(High:)' | sed -e 's/<BR \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<br \/>//'
Or
curl --silent "http://xml.weather.yahoo.com/forecastrss?p= GMXX0154&u=f" | grep -E '(Current Conditions:|F<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/ F<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
---------
Calender: cal
---------
Last Month
cal $( echo $(date +%m)-1 | bc ) $(date +%Y)
Or
cal -m $(date -v-1m +%b)
Or
cal $(date -v -1m ” %m %Y”)
Current Month
(today shown as ** or #)
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./*/g') /"
Or
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"
Or
cal $(date ” %m %Y”)
Next Month
cal $( echo $(date +%m)+1 | bc ) $(date +%Y)
Or
cal -m $(date -v+1m +%b)
Or
cal $(date -v 1m ” %m %Y”)
Month after next
cal $( echo $(date +%m)+2 | bc ) $(date +%Y)
Or
cal -m $(date -v+2m +%b)
---------
You can add / subtract any number of months, and since it's running in the Date command, it won't have issues with the fringe months.
Calendar
cal | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" ");
a=$0; sub(" "fill int(cday)" ","["fill int(cday)"]",a); print a }'
Horizontal
top -l 1| awk 'CPU usage {print $6, $7, $8, $9, $10, $11, $12, $13}'
Vertical
echo CPU usage
top -l 1| awk 'CPU usage {print $8, $9}'
top -l 1| awk 'CPU usage {print $10, $11}'
top -l 1| awk 'CPU usage {print $12, $13}'
Or
CPU
top -l 2 | awk '/CPU usage/ && NR > 5 {print $12, $13}'
Or
top -l 1 | fgrep "CPU usage" | awk '{print "CPU Usage: ", $8}'
CPU hogger!
ps -acx -o %cpu,command | awk '!/0.0/&&!/%CPU/ {if($1>t){t=$1;v=$0}} END{print v}'
Top Processes
top -ocpu -FR -l2 -n20 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24,33-42,64-77
Vertical uptime, CPU
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 }' | sed -e 's/.$//g';
top -l 2 | awk '/CPU usage/ && NR > 5 {print $6, $7=":", $8, $9=""}'
Or
cpu usage: top -l 2 | awk '/CPU usage/ && NR > 5 {print"CPU: " $12, $13}'
Uptime/users/cpu/ram
uptime | awk '{printf "up : " $3 " " $4 " " $5 " " }'; top -l 1 | awk '/PhysMem/ {printf "RAM : " $8 ", " }' ; top -l 2 | awk '/CPU usage/ && NR > 5 {print $6, $7=":", $8, $9="user", $10, $11="sys", $12, $13}'
Memory Usage With Top
top -ocpu -FR -l2 -n20 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24,33-42,64-77
Or
top -orsize -FR -l1 | grep % | grep -v Load | grep -v COMMAND | cut -c 7-19,64-69
Or
top -ocpu -FR -l2 -n5 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24,64-69
Memory Hoggers
top -orsize -FR -l1 | grep % | grep -v Load | grep -v COMMAND | cut -c 7-8,64-69
Change the number 8 to the number of processes you want displayed.
Memory Usage
top -l 1 | awk 'PhysMem {print "Used: " $8}'
Or
top -l 1 | awk '/PhysMem/ {print "" $8 " "}' ;
Or
Vertical
top -l 1 | awk 'PhysMem {print "Free: " $10}'
top -l 1 | awk '/PhysMem/ {print "Capacity: " $8}'
top -l 1 | awk '/PhysMem/ {print "Free: " $10}'
top -l 1 | awk '/PhysMem/ {print "Wired: " $2}'
top -l 1 | awk '/PhysMem/ {print "Active: " $4}'
top -l 1 | awk '/PhysMem/ {print "inactive: " $6}'
amount of RAM used and amount free
top -l 1 | awk '/PhysMem/ {print "Used: " $8 " Free: " $10}'
amount used
top -l 1 | awk '/PhysMem/ {print "RAM: " $8 " "}' ;
3 rows (uptime, RAM(only used), CPU
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 }' | sed -e 's/.$//g'; top -l 1 | awk '/PhysMem/ {print "RAM : " $8 " "}' ; top -l 2 | awk '/CPU usage/ && NR > 5 {print $6, $7=":", $8, $9=""}'
RAM usage-
echo `vm_stat | awk 'BEGIN { FS="[ :.]+"; k=1048576} { if ($(NF-2)=="of") p=$(NF-1); else if ($(NF-2)=="free") f=$(NF-1); else if ($(NF-2)=="inactive") n=$(NF-1); } END { print "RAM:", int(n*p/k)"M/"int(f*p/k)"M" }'` `du -h -I app_profile /private/var/vm | awk '{ print $1 }'`
Disk information: df
Drive Info: df -H -l
df -h | grep disk0s2 | awk '{print "Macintosh HD:", $4, "remaining"}'
change disk0s2 accordingly, and you can add in $2 for total space, and $3 for used space.
df -hl | grep 'disk0s2' | awk '{print $4"/"$2" free ("$5" used)"}'
HD percentage used
echo "Main:" `df -h|grep disk0s2|awk '{print $5}'` change disk0s2 to your disk
$2 gives the capacity, $3 gives the used, $4 gives the free, and $5 gives the percentage used.
diskutil info disk0s2 | grep Verified > /dev/null
Network connections-
netstat -ab -f inet | grep -i established | sort +4
Network activity-
echo "Network Activity:" `((netstat -Ien0 -bn && sleep 4 && netstat -Ien0 -bn) | awk '/Link/ { if (!i) { i=$7; o=$10 } else { i=$7-i; o=$10-o } } END { print int(i/4096)"/" int(o/4096)" kB/s" }') || echo "DOWN"`
IP
for external IP: echo `curl -s checkip.dyndns.org/ | sed 's/[a-zA-Z/ :]//g'`
for internal IP(airport): ifconfig en1 | grep broadcast| awk '{print($2)}'
for internal IP(ethernet): ifconfig en0 | grep broadcast| awk '{print("Internal IP: " $2)}'
ip SHIT-
echo Internal IP: `ifconfig | grep "inet [0-9]"|grep -v 127.0.0.1 | awk '{ print $2 }'`;echo External IP: `curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g'`;echo "";echo "Ethernet (en0):";ifconfig en0|grep "active";echo "Airport (en1):";ifconfig en1|grep "active"
Network Interfaces/External IP:
[myen0=`ifconfig en0 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'`
if [ "$myen0" != "" ]
then
echo "$myen0"
else
echo "Inactive"
fi
myen1=`ifconfig en2 | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'`
if [ "$myen1" != "" ]
then
echo "$myen1"
else
echo "Inactive"
fi
wip=`curl --silent http://checkip.dyndns.org | awk '{print $6}' | cut -f 1 -d "<"`
echo "$wip"]
Source: http://www.macosxhints.com/article.php?story=20090327162020498
Command: osascript /path/to/mailcheck.scpt (replace with the path and name of your own AppleScript).
Script:
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 fromMsg to (sender of thisMessage as string)
set subjMsg to (subject of thisMessage as string)
set finalText to finalText & "- " & word 1 of fromMsg & " " & word 2 of fromMsg & newline & " " & subjMsg & newline
end repeat
end tell
finalText
-------------------------------------------------------------------
set newline to ASCII character 10
set finalText to ""
tell application id "com.apple.mail"
set unreadCount to (get unread count of inbox)
if unreadCount > 0 then
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 fromMsg to (sender of thisMessage as string)
set subjMsg to (subject of thisMessage as string)
set finalText to finalText & i & ". " & fromMsg & newline & " " & subjMsg & newline
end repeat
else
set finalText to "No mail."
end if
end tell
finalText
-------------------------------------------------------------------
#!/bin/sh
#save this as minimonitor.sh somewhere in your path
unreadmail=`/usr/bin/osascript -e "tell application \"Mail\" to set unreadCount to unread count of inbox as string"`;
echo "M: $unreadmail";
echo "-----";
unreadnews=`/usr/bin/osascript -e "tell application \"NetNewsWire\" to set unreadNewsCount to total unread count as string"`;
echo "N: $unreadnews";
And here’s a second one that presents it even smaller, and on one line.
#!/bin/sh
unreadmail=`/usr/bin/osascript -e "tell application \"Mail\" to set unreadCount to unread count of inbox as string"`;
unreadnews=`/usr/bin/osascript -e "tell application \"NetNewsWire\" to set unreadNewsCount to total unread count as string"`;
echo "M:$unreadmail N:$unreadnews";
-------------------------------------------------------------------
set newline to ASCII character 10
tell application "System Events" to set iCalIsRunning to (name of processes) contains "Mail"
set finalText to ""
if iCalIsRunning then
tell application id "com.apple.mail"
set unreadCount to (get unread count of inbox)
if unreadCount > 0 then
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 fromMsg to (sender of thisMessage as string)
set subjMsg to (subject of thisMessage as string)
set finalText to finalText & i & ". " & word 1 of fromMsg & newline & " - " & word 1 of subjMsg & newline
end repeat
else
set finalText to ""
end if
end tell
else
set finalText to ""
end if
FinalText
AppleScript:
tell application "iTunes"
set foo1 to name of current track
set foo2 to player position
set foo3 to duration of current track
set foo4 to foo1 & " " & foo2 & "/" & foo3
end tell
I saved the above script as iTunesName.scpt. Then inside GeekTool, I set my menu-bar-sized window to run the following shell command every 10 seconds:
osascript /path/to/scripts/iTunesName.scpt
------------------------------------------------------------------------------------
Output:
iTunes: Song - Artist (Album) | rating | progress%
if there is no album then that field is dropped
if there is no rating then that field too is dropped
it will cause iTunes to open at login which I think is great!
Script:
tell application "iTunes"
set trackname to name of current track
set artistname to artist of current track
set albumname to album of current track
if albumname is null then
set albumshow to " "
else if albumname is "" then
set albumshow to " "
else
set albumshow to " ( " & albumname & " ) "
end if
set trackduration to duration of current track
set trackposition to player position
set elapsed to round (trackposition / trackduration * 100)
set myRating to round ((rating of current track) / 20)
if myRating is 1 then
set myRating to "| * "
else if myRating is 2 then
set myRating to "| ** "
else if myRating is 3 then
set myRating to "| *** "
else if myRating is 4 then
set myRating to "| **** "
else if myRating is 5 then
set myRating to "| ***** "
else
set myRating to ""
end if
set myRating to myRating
set output to "iTunes: " & trackname & " - " & artistname & albumshow & myRating & "| " & elapsed & "%"
end tell
You can replace the xml file with your RSS link:
curl http://www.macrumors.com/macrumors.xml | sed -e '/title/b' -e '/description/{n;p;}' -e d | sed -e 's/"/"/g' | sed -e 's/<br \/>//g' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'
ComputerName, configuration, etc
scutil --get ComputerName;
sw_vers | awk -F':\t' '{print $2}' | paste -d ' ' - - -;
sysctl -n hw.memsize | awk '{print $0/1073741824" GB RAM"}';
sysctl -n machdep.cpu.brand_string;
-------------------------------------------------------------------
Type some text; echo "yourword"
-------------------------------------------------------------------
System Log- (point it to file)
/var/log/system.log
Daily out- (point to file)
/var/log/daily.out
-------------------------------------------------------------------
Trash Size-- [du -sh ~/.Trash/ | awk '{print $1}']
-------------------------------------------------------------------
Uptime:
uptime | awk '{sub(":", "h ", $3); sub(",", "min", $3); print "Time since last system boot: " $3}'
Or
Uptime-- [uptime | awk '{print "" $3 " " $4 " " $5 " " }']
Or
uptime | awk '{print "" $3 " " $4 " " $5 }' | sed -e 's/.$//g';
-------------------------------------------------------------------
Display iCal Events and a To Do list on your desktop
url: http://www.macosxtips.co.uk/index_files/display-ical-events-to-do-list-on-desktop.html
-------------------------------------------------------------------
Currency convertor
Substitute your own currencies:
dolar to rupee
echo -n '$=EUR ' ; curl --silent 'http://www.google.com/finance/converter?a=1&from=USD&to= EUR' | grep 'USD.* EUR' | sed 's/1 USD = <span class=bld>//' | sed 's/ EUR.*//'
euro to rupee
echo -n 'EUR=INR ' ; curl --silent 'http://www.google.com/finance/converter?a=1&from=EUR&to=INR' | grep 'EUR.*INR' | sed 's/1 EUR = <span class=bld>//' | sed 's/ INR.*//'
Or
echo -n 'EUR=INR ' ; curl --silent 'http://www.google.com/finance/converter?a=1&from=EUR&to=INR' | grep 'EUR.*INR' | sed 's/1 EUR = <span class=bld>//' | sed 's/ INR.*//'
-------------------------------------------------------------------
Adium
osascript /Users/ramesh/Documents/Drives/Extras/Computer/Mac_Tips/Geektools/Adium.scpt
script download: http://www.box.net/shared/pz59kxjajh
To Do List
Create a text file with TextEdit but make sure you click Format>Make Plain Text before save. Then select the file in path in GeekTool.
Main Sources:
Explained for Beginners
http://thememymac.com/2009/geektool/geektool-all-the-scripts-i-could-find-explained-for-beginners/
http://nicinabox.com/geektool/readme.htm
http://forums.macrumors.com/showthread.php?t=628023
http://www.macosxtips.co.uk/index_files/archive-2009.html
http://dump.scratchdrive.com/geektool.txt
http://www.klostermaier.de/kwiki/index.php/Stimulus/AgDesktop
http://www.bioneural.net/2009/03/01/desktop-refits-with-geektool-and-friends/
Also you can see this,
http://nicinabox.com/projects/geektool-scripts/
http://www.flickr.com/photos/grantlucas/3461169720/
http://www.flickr.com/photos/nic-h/3200534321/
http://www.keynote2keynote.com/?p=119&akst_action=share-this
http://www.flickr.com/photos/crbrasington/3208952107/
Calendar:
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /"
RAM
top -l 1 | awk '/PhysMem/ {print "Free: " $10}'
top -l 1 | awk '/PhysMem/ {print "Wired: " $2}'
top -l 1 | awk '/PhysMem/ {print "Active: " $4}'
top -l 1 | awk '/PhysMem/ {print "inactive: " $6}'
Uptime
uptime | awk '{print "UPTIME : " $3 " " $4 " " $5 }' | sed -e 's/.$//g';
Disk
df -h | grep disk0s2 | awk '{print "Macintosh HD:", $4, "remaining"}'
CPU
top -l 1| awk '/CPU usage/ {print $8, $9, $10, $11, $12, $13 }'
Currency
curl --silent 'http://www.google.com/finance/converter?a=1&from=EUR&to=INR' | grep 'EUR.*INR' | sed 's/1 EUR = <span class=bld>//' | sed 's/ INR.*//'
Weather
curl --silent "http://weather.yahooapis.com/forecastrss?p=GMXX0154&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
Forecast
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=GMXX0154&u=c" | grep -E '(High:)' | sed -e 's/<BR \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<br \/>//'
Top 5 cpu hogger
top -ocpu -FR -l2 -n5 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 7-24,64-69
Day of the week
date +%a
Date
date +%d
Month
date +"%B"
Time
date '+%I:%M'
Time-zones
TZ=IST/UTC-5:30 date +"Chennai: %I:%M %p %a"
TZ=NewYork/GMT4 date +"Washington: %I:%M %p - %a"
Apple Mail: (you need the scpt file)
osascript /Users/ramesh/Documents/Drives/Extras/Computer/Mac_Tips/Geektools/mailcheck7.scpt
Adium unread message count:(you need the scpt file)
osascript /Users/ramesh/Documents/Drives/Extras/Computer/Mac_Tips/Geektools/Adium.scpt