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.

SchneiderMan

macrumors G3
May 25, 2008
8,332
202

Attachments

  • Screen shot 2009-12-09 at 12.04.59 AM.png
    Screen shot 2009-12-09 at 12.04.59 AM.png
    53.6 KB · Views: 112

Chartreux

macrumors newbie
Nov 23, 2009
14
0
Thanks for the script - works great.

How do i set a limit to the amount of content that is displayed?


The GeekTool window will limit the output automatically... resize the window to get more or less lines.
But you can also filter the output through 'head' to limit the number of displayed lines (10 in this example):
Code:
<script-command> | head -10

Or:
Code:
<script-command> | sed 10q


By the way, I squeezed the rss-script into a oneliner:
Code:
ruby -r rss -e 'RSS::Parser.parse("https://www.macrumors.com/macrumors.xml").items.each {|item| puts "#{item.date.strftime("%H:%M")}  #{item.title}"}'

Gives:
Code:
19:31  Apple Looking to Revive 'Think Different' Advertising Campaign?
19:11  Apple Rolls Out Customizable Digital iTunes Gift Cards Via Facebook
18:00  AT&T Addressing Network Performance in Manhattan and San Francisco, High-Bandwidth Users
17:38  Ustream Offers Live Video Streaming for the iPhone
15:25  Analyst: Apple Prepping February Tablet Production Ramp Ahead of March or April Release
15:02  Apple Reportedly Preparing to Seed Builds of Mac OS X 10.6.3 to Developers
21:02  'Dragon Dictation' Brings Voice Transcription to the iPhone [Updated]
16:43  Google Releases Chrome for Mac Beta
...
 

RogersDA

macrumors 6502
Aug 19, 2009
271
0
Yeah thats what I was thinking....I was wondering if there might be a new link..??..

There is this post with one QOTD. That shows a lot of quotes.

I updated that code for Encyclopaedia Britannica - but that site does not have the quoter's name.
Code:
#!/usr/bin/ruby

require 'rss'

rss = RSS::Parser.parse 'http://www.britannica.com/feeds/qotd.rss'

puts rss.channel.title,""

rss.items.each do |item|
  puts "#{item.description.sub(/<.*/m,'').strip} - #{item.title}"
end
 

Chooch

macrumors newbie
Dec 9, 2009
3
0
There is this post with one QOTD. That shows a lot of quotes.

I updated that code for Encyclopaedia Britannica - but that site does not have the quoter's name.
Code:
#!/usr/bin/ruby

require 'rss'

rss = RSS::Parser.parse 'http://www.britannica.com/feeds/qotd.rss'

puts rss.channel.title,""

rss.items.each do |item|
  puts "#{item.description.sub(/<.*/m,'').strip} - #{item.title}"
end
Thanks
 

fr3ak

macrumors newbie
Dec 8, 2009
3
0
The GeekTool window will limit the output automatically... resize the window to get more or less lines.
But you can also filter the output through 'head' to limit the number of displayed lines (10 in this example):
Code:
<script-command> | head -10

Or:
Code:
<script-command> | sed 10q


By the way, I squeezed the rss-script into a oneliner:
Code:
ruby -r rss -e 'RSS::Parser.parse("https://www.macrumors.com/macrumors.xml").items.each {|item| puts "#{item.date.strftime("%H:%M")}  #{item.title}"}'

Gives:
Code:
19:31  Apple Looking to Revive 'Think Different' Advertising Campaign?
19:11  Apple Rolls Out Customizable Digital iTunes Gift Cards Via Facebook
18:00  AT&T Addressing Network Performance in Manhattan and San Francisco, High-Bandwidth Users
17:38  Ustream Offers Live Video Streaming for the iPhone
15:25  Analyst: Apple Prepping February Tablet Production Ramp Ahead of March or April Release
15:02  Apple Reportedly Preparing to Seed Builds of Mac OS X 10.6.3 to Developers
21:02  'Dragon Dictation' Brings Voice Transcription to the iPhone [Updated]
16:43  Google Releases Chrome for Mac Beta
...

You're the man!, thx alot!

I'm using your one line of rss code now, works like a charm :)
 

RogersDA

macrumors 6502
Aug 19, 2009
271
0
EDIT: The below script works, but only shows --meaningful-- results when uptime > 1 day.

Better uptime script

Code:
#!/usr/bin/ruby
require 'date'

(now, _, dd, _, _, dhm) = `uptime`.split(/ +|,/)
(dd, dh, dm) = dd.to_i, *dhm.split(':').map { |x| x.to_i }
puts "Uptime -------> #{dd} days, #{dh} hours, #{dm} minutes"

dh += (dm / 60.0)
dd += (dh / 24.0)

last = DateTime.parse(now) - dd

puts "Last Reboot --> #{last.day} #{Date::ABBR_MONTHNAMES[last.mon]} #{last.year} at #{last.hour}:#{last.min}"

This gives an output like:
Uptime -------> 1 days, 11 hours, 43 minutes
Last Reboot --> 9 Dec 2009 at 11:24
 

raltenbach

macrumors newbie
Oct 5, 2009
20
0
Thanks to everyone here! This has been a great lesson in very simple code writing. Here's what I managed to put together with all of your help.
4178497397_afbca024a8_b.jpg
 

raltenbach

macrumors newbie
Oct 5, 2009
20
0
Does anyone have a Geektool script for Battery percentage that works with Snow Leopard?

Thank you.

Here's what I use (gives JUST the percentage):

Code:
#!/bin/bash

asbreg=`ioreg -rc "AppleSmartBattery"`

maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;

prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;

printf "%1.0f%%" ${prcnt};

#EOF

Not very elegant, but it gets the job done.
 

Saul89

macrumors newbie
Nov 21, 2009
4
0
Here's what I use (gives JUST the percentage):

Code:
#!/bin/bash

asbreg=`ioreg -rc "AppleSmartBattery"`

maxcap=`echo "${asbreg}" | awk '/MaxCapacity/{print $3}'`;
curcap=`echo "${asbreg}" | awk '/CurrentCapacity/{print $3}'`;

prcnt=`echo "scale=2; 100*$curcap/$maxcap" | bc`;

printf "%1.0f%%" ${prcnt};

#EOF

Not very elegant, but it gets the job done.


Perfect! Does exactly what I need it to. Thank you!!
 

raltenbach

macrumors newbie
Oct 5, 2009
20
0
This is my other attempt at a comic inspired desktop. Most of the text is dynamic, including the dialog bubble "Afraid to die on a (insert day of week)?". The "I'd been up for..." part is my system's uptime. The rest is pretty obvious stuff. I fear that this damn program is going to eat up WAAAAY to much of my time.:p
4180465754_e9ce95f2ce_b.jpg
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.