Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.
Haha WAY over my head but the coding works perfectly. Thank you :)


On a similar note, has anyone figured out how to display the next month calendar correctly? All of the codes that have been posted put up January 2009 when I try them..

Wow...I noticed the change over, but not that it was 2009. Wonder what could mess the code up.
 
Could somebody please help me with a script that shows a random line from a text file.

On the command line:
Code:
ruby -e 'x = ARGF.to_a; puts x[rand x.size]' [I]somefile.txt[/I]

Or if you prefer a script:
Code:
#!/usr/bin/ruby

x = ARGF.to_a

puts x[rand x.size]

And run the script with somefile.txt as an argument.
 
Wow...I noticed the change over, but not that it was 2009. Wonder what could mess the code up.
Does this help? This is the 3-month calendar I'm using and got the script from this thread.
Code:
#!/bin/zsh

month=`date +%m`
year=`date +%Y`

nextMonth=$(($month+1))
lastMonth=$(($month-1))

if [[ $month -eq 1 ]]
then
        lastMonth=12
        cal $lastMonth $(($year-1)) | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
else
        cal $lastMonth $year | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
fi

cal | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" "); print " "$0; getline; print " "$0; while (getline != 0) {a=" "$0" "; sub(" "fill int(cday)" ",fill "(" int(cday)")", a); print a }}'

if [[ $month -eq 12 ]]
then
        nextMonth=1
        cal $nextMonth $(($year+1)) | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
else
        cal $nextMonth $year | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
fi
 
3 month calendar

Does this help? This is the 3-month calendar I'm using and got the script from this thread.
Code:
#!/bin/zsh

month=`date +%m`
year=`date +%Y`
...

Another version, should do exactly the same:
Code:
#!/bin/bash

# Helper function to display a month in the past or future
Cal() { cal $(date -v$1m '+%m %Y') | sed 's/^/ /';}

# Previous month
Cal -1

# Current month, put parenthesis around current day
# Replace (\\1) by [\\1] to display square brackets for example
ruby -e 'print `cal`.gsub(/^/, " ").sub(/ \b(#{Time.now.day})\b ?/,"(\\1)")'

# Next month
Cal +1

Looks like this:
Code:
    November 2009
 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
 
    December 2009
 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 31
 
     January 2010
 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
 31
 
Does this help? This is the 3-month calendar I'm using and got the script from this thread.

SNIP

Yep. Thanks for the help. I edited the code to remove the previous month for those that don't need that much calendar information.

Code:
#!/bin/zsh

month=`date +%m`
year=`date +%Y`

nextMonth=$(($month+1))
lastMonth=$(($month-1))

cal | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" "); print " "$0; getline; print " "$0; while (getline != 0) {a=" "$0" "; sub(" "fill int(cday)" ",fill "(" int(cday)")", a); print a }}'

if [[ $month -eq 12 ]]
then
        nextMonth=1
        cal $nextMonth $(($year+1)) | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
else
        cal $nextMonth $year | awk '{ print $0; while (getline != 0 ) { print " "$0 }}'
fi
 
Chartreux,

That is an EXCELLENT calendar script.

Can it be revised so it lists the calendars
going across instead of down?
 
Thanks for all the help everyone :D My desktop is finally back to the way I like it.

Screen%20shot%202009-12-03%20at%204.14.30%20PM.png
 
Okay, I'll try help as much as I can :p

Alright so you need lynx, a download can be found here.

Once you have downloaded lynx, install it, and move the file lynx.command to your applications folder, and that's all you need to worry about!

Now for the weather and conditions, I have created a conjoined script so they both get updated and move together as one, Here is the code.

Code:
lynx -dump [B]http://printer.wunderground.com/global/stations/94767.html[/B]|awk '/Cond/ && !/Fore/ {for (i=2; i<=10; i++) printf $i " " }''/Temp/{printf $2, ": "; for (i=3; i<=3; i++) printf $i " " }'

The URL I set in bold is the url for my country and city (Sydney, Australia); So you must go to http://www.wunderground.com/ and put in your details of your whereabouts, go to the link with all the weather updates, and replace my url, with your new one. Remember to keep |awk and put http://printer. (enter url here)

Hope I could help!




Sorry to be a pain, but as you can see from my FIRST, few hours with geektool, and just this forum, thanks for that,
I just can not get, the weather for my place, I have gone to the website in question, and entered my local (de551ll, alfreton), but as you can see it just puts the words, "conditions"

I have read many of the weather posts, but just cant get it to work.

Also why I'm here, my plans are to add further speech bubbles like the 1 I have added to lisa,to contain things like itunes play list, cpu or any other recommendations you care to throw forward.

So guys, hope someone can help this noob.



mydt.png
 
Chartreux,

That is an EXCELLENT calendar script.
Thanks!

Can it be revised so it lists the calendars
going across instead of down?

Of course:
Code:
#!/usr/bin/ruby

def cal offset
  `cal $(date -v#{offset}m "+%m %Y")`.to_a
end

`cal`.gsub(/^/,' ').sub(/ \b(#{Time.now.day})\b ?/,'(\1)').zip(cal('-1'), cal('+1')) {|cur, prv, nxt|
  printf '%-23s', prv.chomp
  printf '%-25s', cur.chomp
  puts nxt
}

Result:
Code:
   November 2009           December 2009            January 2010
Su Mo Tu We Th Fr Sa    Su Mo Tu We Th Fr Sa    Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7           1  2 (3) 4  5                    1  2
 8  9 10 11 12 13 14     6  7  8  9 10 11 12     3  4  5  6  7  8  9
15 16 17 18 19 20 21    13 14 15 16 17 18 19    10 11 12 13 14 15 16
22 23 24 25 26 27 28    20 21 22 23 24 25 26    17 18 19 20 21 22 23
29 30                   27 28 29 30 31          24 25 26 27 28 29 30
                                                31
 

Attachments

  • 3mcal.rb.zip
    345 bytes · Views: 121
Sorry to be a pain, but as you can see from my FIRST, few hours with geektool, and just this forum, thanks for that,
I just can not get, the weather for my place, I have gone to the website in question, and entered my local (de551ll, alfreton), but as you can see it just puts the words, "conditions"

So guys, hope someone can help this noob.

Maybe this will help:
Code:
curl --silent http://printer.wunderground.com/cgi-bin/findweather/getForecast?query=alfreton | ruby -e 'puts ARGF.read.match(/Current Conditions.*?<h3>.*?:\s*(.+?)(?:°)?<\/h3>.*?<h4>(.+?)<\/h4>/m).captures'

Result:
Code:
39.2
Partly Cloudy
 
Chartreux,

THANK YOU SO MUCH.

I am at work now so I can't test it, but
it looks like it will work.

FINALLY a 3-month calendar going across
the screen with the current day indicator.

Can't tell you how happy this makes me.

Thank you again.
 
appreciate the help mate, but serisouly not 2 seconds ago, I managed to get this working,

I used a combination of....this youtube video from...CoolEnufForaMac
and the script on page 48 of this thread.

But the impotant bit for me that has caused a lot of problems, was make sure I went to yahoo weather feed, entered my area, then clicked the RSS button, and got the area code from the address url,and pasted that into the right place on the script on page 48.
Long winded I know ...but

...all in all I get this.....


weatherworking.png



Now all in all guys, I've had a mac for about 2 months, this is my first ever go on geektool, but bar a few hiccups, really enjoyed it, and these forums have been invaluable, .
My next plans are the speech bubble you see, putting some stuff in there, or I may play with putting what I have already in there...

So I may return tomorrow, lol
thanks again guys.
 
I don't like my CPU usage code that much but it was the only one I could get to work, any help?

I really like this code but when I put this is nothing shows up

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}'

Screenshot2009-11-21at115218AM.png

hey where did you get that wallpaper...thats kick ass
 
i love geektool it kicks ass,this thread is very informative,i saw some desktops with the time and date feature and i liked it so when i found this thread i hit the jackpot thanks for posting those script codes i think that saved alot of time,at first i had trouble cause i put all the codes in one entry and it looked boring so thats when i used my geek brain and i figured it out i put in 4 seperate entries by the way...i like the minimalist look i do not like too much clutter on my desk top and i didnt like the calendar or the temperture feature so heres my design:

Picture1.png
 
Chartreux,

Hate to do this to you....

Finally plugged your calendar code in.

The calendar does display itself across.

Problem is, the bottom set of calendar
days are not aligning themselves properly.

Wish I could post a picture/screenshot,
but essentially the 27, 28, 29, 30...etc. on
each calendar is being pushed to the right
into the former month calendar.

Could you test that code and let me know?

Thanks so much.
 
I don't like my CPU usage code that much but it was the only one I could get to work, any help?

I really like this code but when I put this is nothing shows up

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}'
The command: top -l 1
has a rather extensive output. Just place that as your shell script and you will see all the output.

In particular, you are trying to get the information from a specific line. On my computer the CPU usage information is on line 4 of the above command. Line 4's output is, for me, something like:

CPU usage: 2.94% user, 11.76% sys, 85.29% idle

Based on the above the awk space-delimited values for line 4 are:
$1 --> CPU
$2 --> usage:
$3 --> 2.94%
$4 --> user,
$5 --> 11.76%
$6 --> sys,
$7 --> 85.29%
$8 --> idle

So, my shell script is as follows (with the text formatted with a fixed-width font)
Code:
echo CPU Usage
top -l 1| awk 'NR==4{print "System --> "$5}'
top -l 1| awk 'NR==4{print "User ----> "$3}'
top -l 1| awk 'NR==4{print "Idle ----> "$7}'

or
Code:
echo CPU Usage
top -l 1| awk '/CPU Usage/{print "System --> "$5}'
top -l 1| awk '/CPU Usage/{print "User ----> "$3}'
top -l 1| awk '/CPU Usage/{print "Idle ----> "$7}'

This gives me a output of
CPU Usage
System --> 11.76%
User ----> 2.94%
Idle ----> 85.29%

And, yes, these can be combined into one line. I formatted it to display it as four lines. The single shell script
Code:
top -l 1| awk 'NR==4{print $0}'
or
Code:
top -l 1| awk '/CPU usage/{print $0}'
would out all space delimited values (that is what $0 is for) on line 4 (that is what NR==4 or the /CPU usage/ is for).
 
Chartreux,

Hate to do this to you....

Finally plugged your calendar code in.

The calendar does display itself across.

Problem is, the bottom set of calendar
days are not aligning themselves properly.

Wish I could post a picture/screenshot,
but essentially the 27, 28, 29, 30...etc. on
each calendar is being pushed to the right
into the former month calendar.

Could you test that code and let me know?

Thanks so much.
Did yout use a fixed-width font for this shell script? I used it with the fixed-width font and it shows/aligns just fine.
 
Thanks!



Of course:
Code:
#!/usr/bin/ruby

def cal offset
  `cal $(date -v#{offset}m "+%m %Y")`.to_a
end

`cal`.gsub(/^/,' ').sub(/ \b(#{Time.now.day})\b ?/,'(\1)').zip(cal('-1'), cal('+1')) {|cur, prv, nxt|
  printf '%-23s', prv.chomp
  printf '%-25s', cur.chomp
  puts nxt
}

Result:
Code:
   November 2009           December 2009            January 2010
Su Mo Tu We Th Fr Sa    Su Mo Tu We Th Fr Sa    Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7           1  2 (3) 4  5                    1  2
 8  9 10 11 12 13 14     6  7  8  9 10 11 12     3  4  5  6  7  8  9
15 16 17 18 19 20 21    13 14 15 16 17 18 19    10 11 12 13 14 15 16
22 23 24 25 26 27 28    20 21 22 23 24 25 26    17 18 19 20 21 22 23
29 30                   27 28 29 30 31          24 25 26 27 28 29 30
                                                31

I pasted your code into a new shell and it didn't work. Hmmmm?
 
I pasted your code into a new shell and it didn't work. Hmmmm?

Well, it's a Ruby script, not shell commands, so pasting it in a shell won't work...

You have to save it in a file, make it executable (chmod +x) and run the script.

I attached the script for a direct download to my previous post, but I guess you missed it :)
 

Attachments

  • 3mcal.rb.zip
    345 bytes · Views: 126
OK, I have tried several different variations of the scripts to get the DOW, NASDAQ and S&P 500. None of them are working or working the way I need them too. With a little playing around I can get the NASDAQ to display but only how far it is up or down, not what it closed at. Does anyone have a good script for this?
 
OK, I have tried several different variations of the scripts to get the DOW, NASDAQ and S&P 500. None of them are working or working the way I need them too. With a little playing around I can get the NASDAQ to display but only how far it is up or down, not what it closed at. Does anyone have a good script for this?

Here is my script for the DOW, works fine.

Code:
curl http://www.google.com/finance?q=INDEXDJX:.DJI | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/DOW: /g'

Output is:
DOW: 10,388.90 +22.75 (0.22%)

Just modify the URL and the label at the end for other stocks, and you're good to go.
 
Here is my script for the DOW, works fine.

Code:
curl http://www.google.com/finance?q=INDEXDJX:.DJI | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/DOW: /g'

Output is:
DOW: 10,388.90 +22.75 (0.22%)

Just modify the URL and the label at the end for other stocks, and you're good to go.
Just remember - continuously pinging Google for stock data will trigger their servers to block your IP. So watch your refresh rate settings in the GeekTools scripts.
 
Well, it's a Ruby script, not shell commands, so pasting it in a shell won't work...

You have to save it in a file, make it executable (chmod +x) and run the script.

I attached the script for a direct download to my previous post, but I guess you missed it :)

No. I missed the ruby part. Dumb me.
 
Well, it's a Ruby script, not shell commands, so pasting it in a shell won't work...

You have to save it in a file, make it executable (chmod +x) and run the script.

I attached the script for a direct download to my previous post, but I guess you missed it :)
Interesting - I copied and pasted this verbatim right into geektools ver. 3 running on a MacPro. It works w/o chmod. See attached screenshot.

Click to see it bigger.

 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.