I’ve significantly altered the Geek Tool weather script from a previous posting. I switched from using the Weather Underground to using the same weather source as the Apple widget - Accuweather. I got annoyed when the weather widget and my desktop were in disagreement. In addition, the new script is significantly more reliable.
If you’re upgrading from the previous script, be warned that the command line options are now different.
You can find the new weather script here. The new script has the capability of choosing from weather icons as well. You’ll have to download those icons yourself but you can choose from various styles. The official Accuweather icons are located here.
To use this script, copy it to a directory of your choosing, for example /Users/yourusername/bin/acweather.rb. Make it executable by opening up a Terminal window and typing: ‘chmod +x /Users/yourusername/bin/acweather.rb’.
If you want to use the icons, you’ll need to download one of the icon sets from Accuweather and unzip them them in a location of your choosing. By default, the script will look for them in the same directory as the script itself. You can place them elsewhere if you like and pass in a command line parameter to the script, e.g., ‘–iconlocation /Users/yourusername/icons’.
The script uses the Ruby gem ‘trollop’ to parse command-line parameters. If you don’t already have it installed, type ‘sudo gem install trollop’ from the command line to install it. If you’re not sure you have it installed, you don’t. Go ahead and install it, it won’t hurt if you try to install it a second time. The sudo command will ask for your password, it’s your normal login password.
The script requires you to pass in your zip code to choose your weather location, the command line looks like ‘–zipcode 12345’. You don’t need to edit the script.
Here’s the help screen from the script:
--zipcode, -z : Zipcode to retrieve weather for --summary, -s: Short summary of current conditions --forecast, -f: Long-term weather forecast --humidity, -h: Current humidity --longtemperature, -l: Current temperature in long form --temperature, -t: Current temperature --realfeel, -r: Current RealFeel temperature --current, -c: Current conditions --icon, -i: Weather icon --iconlocation, -o : Directory containing weather icons --date, -d: Date the weather was created --lookup, -k : Lookup a city postal code --help, -e: Show this message
So a normal command line would look like: ‘/Users/yourusername/bin/acweather.rb –zipcode 12345 –iconlocation /Users/yourusername/icons –temperature’. Which would print out the current temperature for the zip code 12345.
Update: Frank reminded me that I forgot to explain how to use the weather icon.
GeekTool can only display an image from a set location. So the script copies the current weather icon to ‘/tmp/acweather-icon.png’ every time it runs. In GeekTool you create a new entry, selecting ‘Picture’ instead of ‘Shell’ and fill in the URL box with the text ‘file:///tmp/acweather-icon.png’.
When your other weather script entries run - to get the current temperature or whatever - they’ll copy the icon to /tmp/acweather-icon.png. Your Picture entry will pick up the change after the interval you set in GeekTool.
Update 2: Patrick reported a bug. The script wasn’t returning back forecast data. This is fixed. Please download the script again to get the fix.
|Update 3: A2f reported that the script didn’t work outside the US. I’ve fixed it up both so it works for postal codes outside the US and also so you can use the script to lookup your postal code. For example: A2f lives in Ankara, so the command line to get the weather there is ‘acweather.rb –zipcode “MEA||TR||TU007||ANKARA||”’. You need the double quotes to keep the command line from parsing the pipe (‘||’) characters.|
You can lookup your postal code with the new –lookup option. So, the command line ‘acweather.rb –lookup “ankara, turkey”’ displays the results:
Location = Postal code/Zipcode Ankara, Turkey(Ankara) = MEA|TR|TU007|ANKARA|
Update 4: John VanOphem wrote me with this additional information.
“I figured out how to convert the temps to Celsius easily. You need to add “&metric=1” to the URL. I hard-coded it in and changed the references to C from F but I am sure it would be easy to add it as a new command line option. Using “&metric=0” results in Imperial measurements, so all that really needs to change is the number. It looks like the pressure doesn’t change though(?), so that might still need to be converted if it gets used.”
Categories: Mac ComputerGeek Tool, Mac Computer, Ruby Language