Amazon.com Widgets

Make Your Mac Tell You Weather and Time

How many of you saw the part in Iron Man where the girl is awakened in the morning by Jarvis? I thought that it was just TOO COOL!
In case you didn’t, here is a clip.

After seeing that my brain started to click and I though that could easily be done on an Apple Mac Computer.

See the Mac and say out loud anything you tell it to say. All you have to do is type in “Say” and something to follow. The command is simply Say. So if I wanted the computer to say that “I am on the internet” I would type at the cmd line or terminal, SAY I am on the internet and I press enter and it would speak it. Very neat.

I want my computer to tell me the weather forecast and time every morning, or at least on weekdays.

For you Apple Script folk here is the script to do it. Download here

Or you can copy the following and paste it into your applescript editor and save it:

–this is the city code. Search the code for your city on http://weather.yahoo.com/ set CityCode to 12774701 –temperature format set t_format to “F” –voiceover format set v_format to “S” –say present condition set a_format to “Y”

set IURL to “http://weather.yahooapis.com/forecastrss?w=” & CityCode

–downloading the file using curl set file_content to (do shell script “curl ” & IURL) –looking for the line with actual condition set theText to text ((offset of “yweather:condition” in file_content) + 1) thru -1 of file_content set sub_1 to text ((offset of “\”” in theText) + 1) thru -1 of theText

–today conditions found set actual_condition to text 1 thru ((offset of “\”” in sub_1) – 1) of sub_1

–looking for actual temperature temperature set sub_1a to text ((offset of “temp=” in sub_1)) thru -1 of sub_1 set sub_1b to text ((offset of “\”” in sub_1a) + 1) thru -1 of sub_1a set actual_temp to text 1 thru ((offset of “\”” in sub_1b) – 1) of sub_1b

if t_format is equal to “C” then set actual_temp to (5 / 9) * (actual_temp – 32) as integer end if

–looking for today forecast set theText to text ((offset of “yweather:forecast” in file_content) + 1) thru -1 of file_content set sub_2 to text ((offset of “\”” in theText) + 1) thru -1 of theText

–maximum and minimum temperatures found set today_min_temp to word 9 of sub_2 set today_max_temp to word 12 of sub_2 if t_format is equal to “C” then set today_min_temp to (5 / 9) * (today_min_temp – 32) as integer set today_max_temp to (5 / 9) * (today_max_temp – 32) as integer end if

–looking for today forecast condition (a bit tricky) set sub_3 to text ((offset of “text” in sub_2) + 1) thru -1 of sub_2 set sub_4 to text ((offset of “\”” in sub_3) + 1) thru -1 of sub_3 set today_forecast to text 1 thru ((offset of “\”” in sub_4) – 1) of sub_4

–looking for tomorrow forecast set sub_5 to text ((offset of “yweather:forecast” in sub_4) + 1) thru -1 of sub_4 set sub_6 to text ((offset of “\”” in sub_5) + 1) thru -1 of sub_5

–maximum and minimum temperatures found set tomorrow_min_temp to word 9 of sub_6 set tomorrow_max_temp to word 12 of sub_6 if t_format is equal to “C” then set tomorrow_min_temp to (5 / 9) * (tomorrow_min_temp – 32) as integer set tomorrow_max_temp to (5 / 9) * (tomorrow_max_temp – 32) as integer end if

–looking for tomorrow forecast condition (a bit tricky) set sub_7 to text ((offset of “text” in sub_6) + 1) thru -1 of sub_6 set sub_8 to text ((offset of “\”” in sub_7) + 1) thru -1 of sub_7 set tomorrow_forecast to text 1 thru ((offset of “\”” in sub_8) – 1) of sub_8

–VoiceOver Section set myTime to time string of (current date) set myParts to words of myTime set mySpeak to (item 1 of myParts) & ” ” & (item 2 of myParts) & ” ” say “Good morning, it is ” & mySpeak using “Alex” if a_format is equal to “Y” then say “Outside it is, ” & actual_condition & “, and ” & actual_temp & ” degrees ” using “Alex” end if if v_format is equal to “L” then say “Today: ” & today_forecast & “. Temperature: between ” & today_min_temp & ” and ” & today_max_temp & ” degrees. Tomorrow: ” & tomorrow_forecast & “. Temperature: between ” & today_min_temp & ” and ” & today_max_temp & ” degrees” using “Alex” else say “Today: ” & today_forecast & “, between ” & today_min_temp & ” , and ” & today_max_temp & ” degrees. Tomorrow: ” & tomorrow_forecast & “, between ” & tomorrow_min_temp & ” ,and ” & tomorrow_max_temp & ” degrees” using “Alex” say “I say again, Today: ” & today_forecast & “. Temperature: between ” & today_min_temp & ” ,and ” & today_max_temp & ” degrees” end if

 

I later used iCal to schedule it to run on weekdays.
Hope you are creative and have fun with this

Here is a video of me getting the computer to say it.

 





Sponsored Ad

10 Responses to “Make Your Mac Tell You Weather and Time”

  1. Will Says:

    Nice. I might use this if thats ok. One quick question though, how can I take out tomorrows forecast I only want todays.


  2. Scott Russell Says:

    He, do you think you could send me the your shell script, “curl”. I would like to see how you pulled information off the website using a shell script.

    -Scott


  3. USERBYTES Says:


  4. vvk5 Says:

    how to i change it so it reads out ˚C not ˚F


  5. USERBYTES Says:

    –this is the city code. Search the code for your city on http://weather.yahoo.com/ set CityCode to 12774701 –temperature format set t_format to “F” –voiceover format set v_format to “S” –say present condition set a_format to “Y”

    This is at the top of the script


  6. Jordan Krause Says:

    I am from the UK and I would really like to use this on my Mac however when changing the “city code” to my location (UKXX2082) apple script denies it and shows script error’s it there anything I can do to rectify this problem and have it set up for the UK

    Many Thanks 🙂


  7. Alex Says:

    This is really awesome thank you!!!!

    I would like for it read my appointments from the day. I will look into this. (PS if you compile this into an app I would pay $2.00 for it and so would a lot of people!)


  8. Soxmonky Says:

    Is there a way to get the script to change saying “morning” to “afternoon” or “evening” depending on the time day? While searching the web I found one example but it doesn’t seem to work.

    http://hints.macworld.com/article.php?story=2002043001584298


  9. Cambo Says:

    This is awesome!! Is this by chance open source?


  10. Les Says:

    Another way to check your weather on your Mac is to simply look it up in your terminal. Yes, a terminal app called AnsiWeather gives you the weather right from your terminal. No fuss, no muss. Get it here – https://github.com/fcambus/ansiweather

    Here’s a screenshot:
    https://camo.githubusercontent.com/23f3f6f4db91b03ee805ef9ebc2d6ad58adc14ee/687474703a2f2f7777772e63616d6275732e6e65742f636f6e74656e742f323031332f31302f616e7369776561746865722e706e67