I modified Apples’ default “Current Temperature by Zipcode” script that shipped with OSX with a repeat loop to allow you to enter additional Zipcodes…
(*
WSDL URL: http://www.xmethods.net/sd/2001/TemperatureService.wsdl
(IBM WSDL Toolkit 1.1 - compatible version)
*)
-- SET THE DEFAULT VALUES
property SOAP_Endpoint_URL : "http://services.xmethods.net:80/soap/servlet"
property SOAP_app : "rpcrouter"
property method_name : "getTemp"
property method_namespace_URI : "urn:xmethods-Temperature"
property SOAP_action : ""
-- QUERY USER FOR THE ZIPCODE
repeat
set this_text to "78621"
repeat
try
display dialog "Check Temperature by Zipcode" & return & return & ¬
"Enter the 5-digit zipcode to check:" default answer this_text
set this_text to the text returned of the result
if this_text is not "" and ¬
the length of this_text is 5 and ¬
(this_text as number) is greater than 0 and ¬
(this_text as number) is less than 100000 then
set this_zipcode to this_text as string
exit repeat
else
error
end if
on error number error_number
if the error_number is -128 then error number -128
beep
end try
end repeat
-- CREATE THE PARAMETER RECORD
set the method_parameters to {zipcode:this_text}
-- CALL THE SOAP SUB-ROUTINE
copy my SOAP_call(SOAP_Endpoint_URL, SOAP_app, method_name, method_namespace_URI, method_parameters, SOAP_action) to {call_indicator, call_result}
if the call_indicator is false then
beep
display dialog "An error occurred." & return & return & call_result buttons {"Cancel"} default button 1
else
-- CONVERT THE RESPONSE TO FAHRENHEIT AND CELSIUS
set this_temp to the call_result as number
if this_temp is -999 then
display dialog "No temperature information is available for zipcode " & this_zipcode & "." buttons {"OK"} default button 1
else
set temp_F to this_temp as degrees Fahrenheit
set temp_C to (round ((temp_F as degrees Celsius) as number)) as string
set temp_F to (round (temp_F as number)) as string
display dialog "The current temperature in zipcode " & this_zipcode & " is: " & ¬
return & return & ¬
temp_F & "º Fahrenheit" & return & temp_C & "º Celsius" buttons {"New Zip Code", "Cancel"} default button 2
end if
end if
end repeat
on SOAP_call(SOAP_Endpoint_URL, SOAP_app, method_name, method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application "http://www.apple.com/placebo"
tell application SOAP_app of machine SOAP_Endpoint_URL
set this_result to call soap ¬
{method name:method_name ¬
, method namespace uri:method_namespace_URI ¬
, parameters:method_parameters ¬
, SOAPAction:SOAP_action}
end tell
end using terms from
return {true, this_result}
on error error_message number error_number
if the error_number is -916 then ¬
set the error_message to "The script was unable to establish a connection to the Internet."
return {false, error_message}
end try
end SOAP_call
You can now copy/paste the text from the above ‘Code:’ field into a new Script Editor window, then hit the compile button. So far it seems to work flawlessly.
3 cheers to MacScripter.Net and many many thanks to the phpBB folks.