Contribute
Register

Making Online Notification Services with Applescript

Status
Not open for further replies.
Joined
Dec 3, 2010
Messages
460
Motherboard
Gigabyte GA-H55M-S2V
CPU
Intel i3-530
Graphics
HIS HD 6570
Mac
  1. iMac
Mobile Phone
  1. Android
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).
4lSgdFJ.png

  1. Open Applescript Editor and paste the script at the bottom of the page into the document
  2. Edit the zipcode at the top of the script to your local zipcode, or whichever zipcode's weather you're interested in
  3. 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.
  4. 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.
  5. Now choose Bundle Contents in the toolbar, then the gear icon, and Reveal in Finder.
  6. Open Info.plist with your favorite text editor, or TextEdit
  7. After LSRequiresCarbon and "<true/>" insert
    Code:
    <key>LSUIElement</key>
    <true/>
  8. Now you can save the file and close all other windows
  9. Open System Preferences > Users & Groups > Login Items, and drag your Applescript app into the list
You're all set! The app will start when you login, and check the weather every four hours, posting a notification when it changes. LSUIElement will keep the app out of the dock, so it doesn't bother you.
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
NB: CDyne.com doesn't do a very good job of handling Applescript's SOAP commands, so Tony has graciously posted a file which will "clean" the commands and forward them on. This file won't be up more than a few weeks.
 
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).
4lSgdFJ.png


  1. Open Applescript Editor and paste the script at the bottom of the page into the document
  2. Edit the zipcode at the top of the script to your local zipcode, or whichever zipcode's weather you're interested in
  3. 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.
  4. 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.
  5. Now choose Bundle Contents in the toolbar, then the gear icon, and Reveal in Finder.
  6. Open Info.plist with your favorite text editor, or TextEdit
  7. After LSRequiresCarbon and "<true/>" insert
    Code:
    <key>LSUIElement</key>
    <true/>
  8. Now you can save the file and close all other windows
  9. Open System Preferences > Users & Groups > Login Items, and drag your Applescript app into the list
You're all set! The app will start when you login, and check the weather every four hours, posting a notification when it changes. LSUIElement will keep the app out of the dock, so it doesn't bother you.
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
NB: CDyne.com doesn't do a very good job of handling Applescript's SOAP commands, so Tony has graciously posted a file which will "clean" the commands and forward them on. This file won't be up more than a few weeks.

Very nice custom weather notification. :thumbup:
 
I'm pretty sure the source data only applies to the US. At any rate, this is merely an example people can try to see this kind of usage in action. Any SOAP (or XML-RPC) service you can find that gives you information you want (stocks, currency exchange, etc), and is better at parsing XML than CDyne, can be used, that's the point.
 
Status
Not open for further replies.
Back
Top