- Joined
- Dec 3, 2010
- Messages
- 460
- Motherboard
- Gigabyte GA-H55M-S2V
- CPU
- Intel i3-530
- Graphics
- HIS HD 6570
- Mac
- Mobile Phone
Many don't know that besides providing basic and advanced system scriptability, Applescript also supports some online services natively. SOAP and XML-RPC are two methods web services use to exchange information, and this article describes how to make a simple Applescript app which retrieves weather information and posts a notification to Notification Center (requires Mavericks). |
|
- Open Applescript Editor and paste the script at the bottom of the page into the document
- Edit the zipcode at the top of the script to your local zipcode, or whichever zipcode's weather you're interested in
- Choose File > Save, then File Format: Application, and Stay open after run handler. You may save it wherever you like, but make sure you have access to it later.
- Run the app, and make sure the service can find weather information for your zipcode. If it can't, you may see things like "NA"; edit the script with a different zipcode and try again.
- Now choose Bundle Contents in the toolbar, then the gear icon, and Reveal in Finder.
- Open Info.plist with your favorite text editor, or TextEdit
- After LSRequiresCarbon and "<true/>" insert
Code:<key>LSUIElement</key> <true/>
- Now you can save the file and close all other windows
- Open System Preferences > Users & Groups > Login Items, and drag your Applescript app into the list
You could even change the icon file in the app you made, so the notifications stand out.
Code:
property zipcode : "00000"
property oldWeather : ""
on idle
tell application "http://tonymacx86.com/WeatherWS/Weather.asmx" to set weather to call soap {method name:"GetCityWeatherByZIP", method namespace uri:"http://ws.cdyne.com/WeatherWS/", parameters:{ZIP:zipcode}, SOAPAction:"http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"}
if (success of weather is "true" and oldWeather is not equal to |description| of weather) then
display notification "Currently " & |description| of weather & ", " & temperature of weather & "˚, wind " & wind of weather with title "Weather Conditions" subtitle city of weather & " (" & weatherstationcity of weather & "), " & state of weather
set oldWeather to |description| of weather
end if
return 4 * 3600
end idle