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.
some one asked this in the first few pages but i didnt see any answers...

Can anyone point me in the right direction of how to get weather status for Canadian cities and not american ones? thank you!

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! :))
 
thanks so much digital life, im just wonderin if theres anyway to display the temprature and the actual forecast (cloudy etc) seperatly base don the line of code you have shared with me? as in be able to have two shell scripts instead of one?
 
thanks so much digital life, im just wonderin if theres anyway to display the temprature and the actual forecast (cloudy etc) seperatly base don the line of code you have shared with me? as in be able to have two shell scripts instead of one?

Hi, yes that's very possible.
If you want it all in one script then just add
Code:
 | tr ',' '\n'
to your command. This will replace the ',' with a newline character.

If you want to split it into 2 scripts (commands) then just add:
Code:
 | tr ',' '\n' | head -n2
for the conditions and
Code:
 | tr ',' '\n' | tail -n1
for the temperature

You could also do it using sed in one shot (instead of using tr and head/tail)..
There are lots of ways of achieving the same result...anyway you should familiarize yourself with these basic shell utils:
Code:
man head
man tail
man tr
man grep
man sed
man awk

Hope it helps! :)
 
Hmmmm.
Updated to GeekTool 3 and my Temperature has disappeared.
This worked perfectly before:

Any ideas? :eek: Thanks!

Hi arkitect.
I'm not sure on this but i'd say it has to do with the 'º' character that displays "strangly"..Try changing the encoding (in Geektool it self).

If it doesn't work just try:
Code:
curl --silent "http://printer.wunderground.com/auto/printer/global/stations/03779.html" | grep -A2 Temperature | tr '\n' ' ' | sed -E 's/.+>([0-9]+\.?[0-9]*).+;(.).+/[COLOR="SandyBrown"]Temperature: [/COLOR]\1 [COLOR="SandyBrown"]º[/COLOR]\2\n/g'
(I tested this in linux not osx but it should work the same)

you can remove the parts in orange if you don't want that text to appear...

Hope it helps!
 
Hi arkitect.
I'm not sure on this but i'd say it has to do with the 'º' character that displays "strangly"..Try changing the encoding (in Geektool it self).

If it doesn't work just try:
Code:
curl --silent "http://printer.wunderground.com/auto/printer/global/stations/03779.html" | grep -A2 Temperature | tr '\n' ' ' | sed -E 's/.+>([0-9]+\.?[0-9]*).+;(.).+/[COLOR="SandyBrown"]Temperature: [/COLOR]\1 [COLOR="SandyBrown"]º[/COLOR]\2\n/g'
(I tested this in linux not osx but it should work the same)

you can remove the parts in orange if you don't want that text to appear...

Hope it helps!

Chiming in about thwe code u posted ot the other member when u paste that in geek tool the output is:

"Temperature 15.8 ºCn"


Any idea where that n came from?
 
Chiming in about thwe code u posted ot the other member when u paste that in geek tool the output is:

"Temperature 15.8 ºCn"


Any idea where that n came from?

Hi, yes that 'n' is from the '\n' (almost) at the end of the command.
Don't know why but i really can't get sed to print a newline character.
It works ok on linux but not on osx.
Just remove the '\n' and it should be fine.
 
also here's my desktop when the weather condition is working right:
Picture1-26.png

Do you have the link to your wallpaper? Searches of "Brad Pitt with Boombox" turned up nothing haha
 
this is what i have come up with for my desktop. all the scripts i have gotten from this thread.
 

Attachments

  • geektool.jpg
    geektool.jpg
    95.5 KB · Views: 344
Ok, I am having e-mail now with the folowing code:

Code:
echo 'tell application "Mail" to return unread count of inbox as string & " new e-mail"' | osascript | grep -v '0 new e-mail'

This returns nothing when there is no mail and x new e-email when there is mail, however it starts mail.app when it is not running, something I don't want it to do.

I had about the same with itunes but it now checks if itunes is running, if its not it won't execute the script. I am not a programmer, but I feel the same is possible for this script. Anyone?

iTunes script:
Code:
property go1 : false
-- check to see if iTunes is running
tell application "System Events"
	set the process_flag to (exists process "iTunes")
end tell
if the process_flag then
	-- check to see if iTunes is playing
	tell application "iTunes"
		if player state contains playing then set go1 to true
	end tell
	if go1 then
		-- do what you need to do
		tell application "iTunes"
			set foo1 to name of current track
			set foo2 to artist of current track
			set foo3 to album of current track
			set foo4 to foo1 & " / " & foo2 & " / " & foo3
		end tell
	end if
end if

I am sure these 2 can sortoff be combined to achieve that same. Even better would be if it would read 1 new email and 2 new emails and so forth.

Thanks

I don't have anything to add for the mail (it may be between your post and this one), but I want to give you thanks for that bit of code. I can now keep my iTunes shell's active at all times and not have iTunes open.

Again, thanks.
 
I don't have anything to add for the mail (it may be between your post and this one), but I want to give you thanks for that bit of code. I can now keep my iTunes shell's active at all times and not have iTunes open.

Again, thanks.
Hi, not 100% sure on this (don't have a mac to test right now) but just replace:
Code:
'tell application "Mail" to return unread count of inbox as string & " new e-mail"'
with
Code:
'tell application "System Events"
	set the process_flag to (exists process "Mail")
end tell
if the process_flag then
	tell application "Mail" to return unread count of inbox as string & " new e-mail"
end if'
(better put it in a script file)

Anyways, what I think you want is to get the unread email count without opening Mail. What this script does is give you the unread email count only when Mail is open.

Hope it helps,
 

Hi, Geektool does not understand Applescript commands (that's what you are puting in the command window).
Geektool only understands command-line....commands!

If you want to use that script that's in your screenshot, the quickest way would be to pipe that script to osascript :
Code:
echo '<your script here>' | osascript

The clean way is to add that script to a file (myscript.scpt for example) and put in geektool
Code:
osascript <path to the scpt file>
Hope it helps,
 
Anybody else having this problem? (I'm using GeekTool 3):

I want to use a .txt file as a label (for example: DATE: xxx TIME: xxx) but for some reason once I point GeekTool to the .txt, it re-loads every time I make a change to it. Change the font, I get two lines. Change the text size, I get three. So now I have:

DATE:
DATE:
DATE:

It's annoying. Why's it doing this?

Sidenote: Is there anyway I can just add text in a shell script using some sort of print command? I don't code much, I usually just plug-and-chug from stuff like this thread, so, sorry if this is a noob question.

i have exactly the same problem when i use "file" to display a .txt file, as a work around i use the shell script
Code:
cat <path to the .txt file>

or to add text to a shell script use
Code:
echo "<your text>"

maybe someone will provide an actual solution to using the file thingy... but i'm probably as much of a noob as you, so hopefully this will help.
 
@DigitalLife

Hey, I've been trying to get my weather to display a specific way and I've been trying to use your code snippets to make it work and have been failing miserably.

What I have now:
Code:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=22903&u=f" | grep -e "Forecast:" -A 2 | tail -n 2 | sed -e 's/<br \/>//' -e 's/<BR \/>//' | sed "s/\(.*\)\.\ \(.*\)/\1\?\2/" | tr "?" "\n" | sed "s/High\:\ \(.*\)\ Low\:\ \(.*\)/\?H\: \1\ L\:\ \2/" | sed "s/\?\(.*\)/\\1/"

screenshot20091027at206.jpg


I'm trying to get this format:

Today: [Conditions], [Hi] | [Low]
[Tomorrow's Day]: [Conditions], [Hi] | [Low]

If you could help I would really appreciate it.
 
@DigitalLife

Hey, I've been trying to get my weather to display a specific way and I've been trying to use your code snippets to make it work and have been failing miserably.

What I have now:
Code:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=22903&u=f" | grep -e "Forecast:" -A 2 | tail -n 2 | sed -e 's/<br \/>//' -e 's/<BR \/>//' | sed "s/\(.*\)\.\ \(.*\)/\1\?\2/" | tr "?" "\n" | sed "s/High\:\ \(.*\)\ Low\:\ \(.*\)/\?H\: \1\ L\:\ \2/" | sed "s/\?\(.*\)/\\1/"

screenshot20091027at206.jpg


I'm trying to get this format:

Today: [Conditions], [Hi] | [Low]
[Tomorrow's Day]: [Conditions], [Hi] | [Low]

If you could help I would really appreciate it.

Hi,
i think this should do the trick.
Code:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=22903&u=f" | grep -e "Forecast:" -A 2 | tail -n 2 | sed -e 's/<br \/>//' -e 's/<BR \/>//' | sed -E '2n;s/.+\-[ ](.+)\..+:[ ]([0-9]+).+:[ ]([0-9]+)/Today: \1, \2 | \3/' | sed -E '1n;s/[ ]\-[ ](.+)\..+:[ ]([0-9]+).+:[ ]([0-9]+)/\: \1, \2 | \3/'
Let me know

extra info: the '2n;' makes sure line 2 is not processed. The same goes for the 1n;

edit2: im using this one for me (warning different city)
Code:
curl --silent "http://xml.weather.yahoo.com/forecastrss?p=POXX0016&u=c" | grep -e "Forecast:" -A2 -B2  |tail -n 4 | grep -v orecast | sed -e 's/<br \/>//' -e 's/<BR \/>//' |  sed -n -E '2n;s/[ ]\-[ ](.+)\..+:[ ]([0-9]+).+:[ ]([0-9]+)/\: \1, \2 | \3/;p'
Instead of using forecast for today and tomorrow, it uses Current Conditions for the "now" and then, the forecast for tomorrow.
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.