This should work (for Toronto)
Code:curl --silent "http://xml.weather.yahoo.com/forecastrss?p=[COLOR="Orange"]CAXX0504[/COLOR]&u=[COLOR="RoyalBlue"]c[/COLOR]" | grep -E '(Current Conditions:|[COLOR="RoyalBlue"]C[/COLOR]<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
Replace text in orange for you city you want weather info on. (browser yahoo weather to the city you want and check it's code on the URL).
If you want Fahrenheit replace the 'c' in blue with 'f'.
Try it first in Terminal. If you get an error saying something about '<' then just escape this character in the command above.(i.e. replace '<' with '\<')
Hope it helps!
Edit: as you can see there's no difference between american cities, canadian cities or any other city around the world. (except for the city code!)
Hi,
I wanted to display a .txt file on my desktop using geektool but I'm experiencing some problems.
First of all I doesn't update when I change the .txt file, I have to log out and back in again to get an update.
Also when I change something in geektool the text from the file is displayed over and over and over again in the entire geektool window.
Does anybody know how to fix this?
Lonnie
Recently my weather scripts have been showing a bit of HTML with the forecast. Anyone had to same problem and/or know how to fix it?
![]()
Typically, the way to do the weather scripts have been to use curl to grab the actual HTML code then use a combination of grep or awk to parse out the data you want to show.
However, websites change. When they do, the old code needs to be updated. Without seeing the code you are using and comparing it against the HTML source, there is no way to advise you specifically. (And also, I have been using Applescript to do my HTML parsing as it's easier for me, so I am a mere beginner at understanding tools like grep and awk)
curl --silent "http://weather.yahoo.com/australia/victoria/melbourne-12708013/?unit=c" | grep -E '<th>Tomorrow</th>' | tr '\011' ' ' | sed -e 's/ //g' -e 's/<th c.*//' -e 's/<\/th><th>/\
/g' -e 's/<\/*th>//g'
curl --silent "http://weather.yahoo.com/australia/victoria/melbourne-12708013/?unit=f" | grep -E 'wiff' | head -n1 | sed -e 's/<img id="wiff" style="background-position: -[0-9]*px -[0-9]*px; width: 61px; height: 34px" alt="" src="http:\/\/l.yimg.com\/a\/lib\/ywc\/img\/spacer.gif"\/>//g' -e 's/<\/*td>//g' -e 's/<\/*div>//g' -e 's/<br\/>/\
/g' | tail -n5 | tr '\011' ' ' | sed -e 's/ .*//g'
Still can't figure out how to get the weather stuff to work - I reinstalled Lynx like 10 times...
err..
Maybe this helps? It's what I used. Didn't fool with Lynx.
http://www.youtube.com/watch?v=uNFkW1lLxtU
top -ocpu -FR -l2 -n20 | grep '^....[1234567890] ' | grep -v ' 0.0% ..:' | cut -c 1-24,33-42,64-77
For those of you who are having problems with Lynx - IT DOES NOT WORK WITH SNOW LEOPARD.
These scripts will give you the weather info you want or you can choose to just use pieces of it! Enjoy!
Weather Image Script:
file:///tmp/weather.png
Weather Grab Image Script:
curl --silent "YOUR_AREA_URL" | grep "forecast-icon" | sed "s/.*background\\:url(\\'\\(.*\\)\\')\\;\\ _background.*/\\1/" | xargs curl --silent -o /tmp/weather.png
____________________________________________________________________
The next two scripts are a little tricky, to get the correct URL, go to Yahoo Weather, and click on RSS in the upper right corner (it's an orange button). Once you do that you'll see an 8 character code, copy that then proceed.
Conditions and Temperature :
Fahrenheit Readout:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=YOUR_AREA_CODE&u=f" | grep -E '(Current Conditions:|F<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
Metric Readout:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=YOUR_AREA_CODE&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>//'
Two Day Forecast:
Fahrenheit:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=YOUR_AREA_CODE&u=f" | grep -E '(High' | sed -e 's/<BR \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<br \/>//'
Metric:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=YOUR_AREA_CODE&u=c" | grep -E '(High' | sed -e 's/<BR \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<br \/>//'
--Date: 7/20/2010 Email:shomann@gmail.com
--Personal or non-commerical use only.
--Yahoo! Weather API used.
--Enter the location of the weather icon FOLDER on your harddrive as URL:
set iconfolder to "file://localhost/Volumes/media/_users/..."
--Enter the WOEID for your location here
--For more information on the WOEID system go here: http://developer.yahoo.com/geo/geoplanet/guide/concepts.html
--To find your WOEID, try here: http://sigizmund.info/woeidinfo/?woeid=texas
set theLoc to "2400767"
--Set unitlogic to true if you are using metric
set unitlogic to "false"
set shell1 to "curl \"http://weather.yahooapis.com/forecastrss?w="
if unitlogic = "false" then
set shell2 to "\""
else
set shell2 to "&u=c\""
end if
set web_content to do shell script (shell1 & theLoc & shell2) as string
set AppleScript's text item delimiters to "\""
--Location
set w_city to text item 14 of web_content
set w_state to text item 16 of web_content
--Units
set w_tempunits to text item 20 of web_content
set w_disunits to text item 22 of web_content
set w_prsunits to text item 24 of web_content
set w_speedunits to text item 26 of web_content
--Begin Current Conditions
--Wind
set w_cur_chill to text item 28 of web_content
set w_winddir to text item 30 of web_content
set w_windspd to text item 32 of web_content
--Atmosphere
set w_humid to text item 34 of web_content
set w_vis to text item 36 of web_content
set w_prs to text item 38 of web_content
set w_prslogic to text item 40 of web_content
--Astronomy
set w_sunrise to text item 42 of web_content
set w_sunset to text item 44 of web_content
-- Condition
set w_curcond_text to text item 46 of web_content
set w_curcond_code to text item 48 of web_content
set w_curcond_temp to text item 50 of web_content
set w_updated to text item 52 of web_content
--Forecast
set w_fore0day to text item 60 of web_content
set w_fore0low to text item 64 of web_content
set w_fore0high to text item 66 of web_content
set w_fore0text to text item 68 of web_content
set w_fore0code to text item 70 of web_content
set w_fore1day to text item 72 of web_content
set w_fore1low to text item 76 of web_content
set w_fore1high to text item 78 of web_content
set w_fore1text to text item 80 of web_content
set w_fore1code to text item 82 of web_content
--Prs logic
if w_prslogic is "1" then
set w_prssymbol to "▲"
else
set w_prssymbol to "▼"
end if
tell application "GeekTool"
set command of shell geeklet "w_loc" to "echo '" & w_city & ", " & w_state & "'"
set command of shell geeklet "w_foreday" to "echo '" & w_fore1day & "'"
set command of shell geeklet "w_temps0" to "echo '" & w_curcond_temp & w_tempunits & "'"
set command of shell geeklet "w_temps1" to "echo '" & w_fore0high & "-" & w_fore0low & w_tempunits & "'"
set command of shell geeklet "w_temps2" to "echo '" & w_fore1high & w_tempunits & "\n" & w_fore1low & w_tempunits & "'"
set image url of image geeklet "w_icon0" to iconfolder & w_curcond_code & ".png"
set image url of image geeklet "w_icon1" to iconfolder & w_fore1code & ".png"
set command of shell geeklet "w_updated" to "echo '" & w_updated & "'"
end tell
return "H: " & w_humid & "% | V: " & w_vis & w_disunits & " | W: " & w_winddir & "° at " & w_windspd & w_speedunits & " | P: " & w_prs & w_prsunits & w_prssymbol & " ◉ " & w_sunrise & " - " & w_sunset
The weather stuff can be tricky. I ended up writing a new Applescript for it, just to try to get a better understanding of it. You really shouldn't need Lynx to get the existing Yahoo Weather info to work though...
I re-wrote my scripts to gather info from the Yahoo Weather API. The advantages are a much simpler parsing routine and a well documented code table for weather conditions. This let me use the Flat Weather icon set to show my weather, rather than pull down the current weather PNG from Yahoo.
Here is the code:
Code:--Date: 7/20/2010 Email:shomann@gmail.com --Personal or non-commerical use only. --Yahoo! Weather API used. --Enter the location of the weather icon FOLDER on your harddrive as URL: set iconfolder to "file://localhost/Volumes/media/_users/..." --Enter the WOEID for your location here --For more information on the WOEID system go here: http://developer.yahoo.com/geo/geoplanet/guide/concepts.html --To find your WOEID, try here: http://sigizmund.info/woeidinfo/?woeid=texas set theLoc to "2400767" --Set unitlogic to true if you are using metric set unitlogic to "false" set shell1 to "curl \"http://weather.yahooapis.com/forecastrss?w=" if unitlogic = "false" then set shell2 to "\"" else set shell2 to "&u=c\"" end if set web_content to do shell script (shell1 & theLoc & shell2) as string set AppleScript's text item delimiters to "\"" --Location set w_city to text item 14 of web_content set w_state to text item 16 of web_content --Units set w_tempunits to text item 20 of web_content set w_disunits to text item 22 of web_content set w_prsunits to text item 24 of web_content set w_speedunits to text item 26 of web_content --Begin Current Conditions --Wind set w_cur_chill to text item 28 of web_content set w_winddir to text item 30 of web_content set w_windspd to text item 32 of web_content --Atmosphere set w_humid to text item 34 of web_content set w_vis to text item 36 of web_content set w_prs to text item 38 of web_content set w_prslogic to text item 40 of web_content --Astronomy set w_sunrise to text item 42 of web_content set w_sunset to text item 44 of web_content -- Condition set w_curcond_text to text item 46 of web_content set w_curcond_code to text item 48 of web_content set w_curcond_temp to text item 50 of web_content set w_updated to text item 52 of web_content --Forecast set w_fore0day to text item 60 of web_content set w_fore0low to text item 64 of web_content set w_fore0high to text item 66 of web_content set w_fore0text to text item 68 of web_content set w_fore0code to text item 70 of web_content set w_fore1day to text item 72 of web_content set w_fore1low to text item 76 of web_content set w_fore1high to text item 78 of web_content set w_fore1text to text item 80 of web_content set w_fore1code to text item 82 of web_content --Prs logic if w_prslogic is "1" then set w_prssymbol to "▲" else set w_prssymbol to "▼" end if tell application "GeekTool" set command of shell geeklet "w_loc" to "echo '" & w_city & ", " & w_state & "'" set command of shell geeklet "w_foreday" to "echo '" & w_fore1day & "'" set command of shell geeklet "w_temps0" to "echo '" & w_curcond_temp & w_tempunits & "'" set command of shell geeklet "w_temps1" to "echo '" & w_fore0high & "-" & w_fore0low & w_tempunits & "'" set command of shell geeklet "w_temps2" to "echo '" & w_fore1high & w_tempunits & "\n" & w_fore1low & w_tempunits & "'" set image url of image geeklet "w_icon0" to iconfolder & w_curcond_code & ".png" set image url of image geeklet "w_icon1" to iconfolder & w_fore1code & ".png" set command of shell geeklet "w_updated" to "echo '" & w_updated & "'" end tell return "H: " & w_humid & "% | V: " & w_vis & w_disunits & " | W: " & w_winddir & "° at " & w_windspd & w_speedunits & " | P: " & w_prs & w_prsunits & w_prssymbol & " ◉ " & w_sunrise & " - " & w_sunset
To break it down, I first have the script gather info from Yahoo Weather APIs. Then I assemble the output for the details of the current conditions, including humidity, visibility, wind, pressure, and sunrise/set. At the end of the script, I tell Applescript to reset the icons and temperature fields inside GeekTool.
I can break it down further, but if you want to use this as is, create two image geeklets named w_icon0 (for current conditions) and w_icon1 for tomorrow's conditions. Then create 3 shell geeklets named w_temps0 (current temp) and w_temps1(today's high low) and w_temps2 (tomorrow's temps).
You will need to modify the script to point to your weather icons folder. Search for Flat Weather icons on deviantArt for the icons I used...
Let me know what you think!
Wallpaper is from interfacelift here.
Script is
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.
This script gives me '100Gi' whereas the bottom of the Finder window gives me 107.89 GB. Anyone know why the discrepancy?
hey guys, never done any kind of script/programming. I loved the idea of geektool, so I "borrowed" some scripts I found online. Let me know how you like my desktop. Its simple but its my first time using geektool.
The itunes isnt geektool but an app called tunesart. Anybody have any ideas what I could put in the big gaping hole middle left? Under the time?
EDIT: Does anybody know how to get rid of Lynx? I know I shouldnt have been messing around with it in the first place, but I was following a pretty simple tutorial, but then ended up changing my mind. I dont have a use for it now and want to get rid of it. Any ideas? I tried appzapper which obviously doesnt work.
Let me know what you think!
Like I'm going to read through 89 pages. Anyway, how does 1024:1000 MB correlate to 107:100 GB? Please teach me the maths.because the script uses 1 000MB / GB while finder uses the real 1 024MB / GB... it was said a few weeks ago...
and for the "uptime" information... when you have a laptop, its always good to restart your computer once in a while... or else it slowly slows down...
Hi,
You do or don't know that your apple counts 1Gb as 1000Mb instead of 1024Mb. Not sure if that is really the problem but it's possible...
Look up the man page of df or try the script with the capital "H"...
ex. df -H | ....
good luck
here ya go MrSmith... i knew it was somewhere!
and for the uptime... i just like having my uptime on my desktop... cuz i dont really know when was the last time i did restart it... and Im not trying to be the "captain of the enterprise"... i just like to have info on my computer...