AppleScript/Project Builder help

Ok I am having trouble with this AppleScript. I have a button in an interface I made and I want to link the follwing AppleScript to it. So then it adds “on mouse up theObject event theEvent” at the begining and “end mouse up” and the end. So the problem is this… This works fine with a regular AppleScript but all of mine are internet services… here is what I think the problem is… in project builder when I click anything but the things in red i the little menu it says “on mouse up” but when you click the ones that say PROPERTY (Red) then it says that property instead of “on mouse up” and project builder wont let me put “on mouse up theObject event theEvent” in front of the properties it then says that it needs to end… i think that is becasue the properties change on those thing in red and it cant becaseue it still needs “on mouse up” ad the property. SO HOW DO I FIX THIS… does anyone know… all help is very apreciated… thanks… here is the script

on mouse up theObject event theEvent
WSDL URL: http://services.xmethods.net/soap/u...yed-quotes.wsdl _
(IBM WSDL Toolkit 1.1 - compatible version)
*)

– SET THE DEFAULT VALUES
property SOAP_Endpoint_URL : “http://services.xmethods.net:80/soap
property SOAP_app : “soap”
property method_name : “getQuote”
property method_namespace_URI : “urn:xmethods-delayed-quotes”
property SOAP_action : “”

– QUERY USER FOR THE STOCK INDICATOR
set this_text to “AAPL”
repeat
try
display dialog “Stock Quote” & return & return & ¬
“Enter the company code:” default answer this_text
set this_text to the text returned of the result
exit repeat
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 {Symbol:this_text}

– CALL THE SOAP SUB-ROUTINE
copy my SOAP_call(SOAP_Endpoint_URL, 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
display dialog "The delayed stock quote for " & this_text & " is: " & call_result buttons {“OK”} default button 1
end if

on SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application “http://www.apple.com/placebo
tell application 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
end mouse up

Have you tried putting the property declarations outside the object handler?

I’ve never tried to use properties in an AStudio app, so that’s mostly a guess.

However, if it’s just a persistent value you’re after, I’d recommend AStudio’s built-in preference model. Very cool, very easy to use. It’ll generate a .plist file for your app and makes for easy fetching of saved values.

Try the following, I was at least able to get it to compile in project builder.

I move the properties, and the SOAP_call handler out of the mouse up handler. I would also question using the mouse up handler as the trigger for the action. on clicked might be better, but you have to make sure that you get to select that in interface builder for the button that you want to trigger the action.

I also added the open comment “(" to match the close comment ")” at the beginning of the handler. Also the event theEvent part seems redundant, you don’t seem to be accessing it in any part of your code.

With AppleScript I would recommend adding little bits of code at a time. I find it difficult to debug and the easiest way to resolve problems is to add small bits at a time and once that works add the next bit. In your case get the user interface stuff working first - (just display a dialog) and once that works add in your soap stuff. Otherwise it is hard to know what doesn’t work.


-- SET THE DEFAULT VALUES 
property SOAP_Endpoint_URL : "http://services.xmethods.net:80/soap"
property SOAP_app : "soap"
property method_name : "getQuote"
property method_namespace_URI : "urn:xmethods-delayed-quotes"
property SOAP_action : ""

on SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action)
	try
		using terms from application "http://www.apple.com/placebo"
			tell application 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

on mouse up theObject event theEvent
	(*  WSDL URL:       http://services.xmethods.net/soap/u...yed-quotes.wsdl _ 
  (IBM WSDL Toolkit 1.1 - compatible version) 
  *)
	
	-- QUERY USER FOR THE STOCK INDICATOR 
	set this_text to "AAPL"
	repeat
		try
			display dialog "Stock Quote" & return & return & ¬
				"Enter the company code:" default answer this_text
			set this_text to the text returned of the result
			exit repeat
		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 {Symbol:this_text}
	
	-- CALL THE SOAP SUB-ROUTINE 
	copy my SOAP_call(SOAP_Endpoint_URL, 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
		display dialog "The delayed stock quote for " & this_text & " is: " & call_result buttons {"OK"} default button 1
	end if
end mouse up

Thanks so much… it worked

Once again thanks so much… i did the same thing to all my scripts and everything is working perfect i just have one question… i made an ICNS file with the icons i wanted in IconCompser and saved it… now how do i make it work in my application?

Drag the icon into the resources file list in your AppleScript Studio project. Then click on the targets tab, then click on your target (red bulls eye), then in Info.plist entries, click on Application Icon and then enter the name of your icon file there. I would recommend doing a clean (click on the broom) and then building. Finder needs to think that there is something new where the icon is worth caching.

If you do have trouble getting your icon recognized by Finder, first make sure you spelt it right, but logging out and back in again usually does the trick.

If you haven’t done so already I would recommend going through the various options that come up when you have clicked on your target.

Kevin

Thanks

Ok pne more thing… I did this same thing to another one of my scripts, a translate tool… and it compiles and builds and works and everything but when i run it and it asks for a phrase and i press ok i get this instead of the transaled phrase “base64=HASH(0x84ãf44)”

This is the script… can you help?

– french.applescript
– Internet Inform
– SET THE DEFAULT VALUES
property SOAP_Endpoint_URL : “http://services.xmethods.net:80/perl/soaplite.cgi
property method_name : “BabelFish”
property method_namespace_URI : “urn:xmethodsBabelFish”
property SOAP_action : “urn:xmethodsBabelFish#BabelFish”

on SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application “http://www.apple.com/placebo
tell application 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 “Internet Inform was unable to establish a connection to the Internet.”
return {false, error_message}
end try
end SOAP_call
on clicked theObject

(*

WSDL URL: http://www.xmethods.net/sd/2001/BabelFishService.wsdl
(IBM WSDL Toolkit 1.1 - compatible version)
*)
– QUERY USER FOR TEXT TO TRANSLATE
set this_text to “”
repeat
try
display dialog “Enter the text to translate into French:” default answer this_text
set this_text to the text returned of the result
if this_text is not “” then
set this_text to this_text as string
exit repeat
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 {translationmode:"en_fr", sourcedata:this_text}

-- CALL THE SOAP SUB-ROUTINE
copy my SOAP_call(SOAP_Endpoint_URL, 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
	display dialog call_result buttons {"Clipboard", "OK"} default button 2
	if the button returned of the result is "Clipboard" then
		set the clipboard to the call_result
	end if
end if

end clicked
– Created by Chris Wronski on Sat Aug 09 2003.

no one can help? i really need this quick… all help is very apreciated

More information is needed to answer your question. I am not prepared to create my own AppleScript Studio Application to try and work out why the code doesn’t work, and I think most others will be the same.

Therefore for us to help you have to work out where the problem occurs, if you have to put in a few display dialogs to work out where your script goes wrong yourself and then make it clear where things have gone wrong by putting comments in the code for us to see.

Since I can’t see anywhere in your script where base64=HASH(0x84ãf44) could be generated then my only guess is that the soap call generates the response, which would then suggest that the soap call hasn’t been set up correctly. Since I haven’t done any soap stuff I can’t help you there.

cela fonctionne pour moi (It works for me).

I copied your script from above into Script Debugger, changed on clicked to on run and it just worked.

~Ross

The on run thing didnt work because i need on mouse up or on click. this is the original script unchanged which works, i just need it to work when i puch a button
(*
WSDL URL: http://www.xmethods.net/sd/2001/BabelFishService.wsdl
(IBM WSDL Toolkit 1.1 - compatible version)
*)

– SET THE DEFAULT VALUES
property SOAP_Endpoint_URL : “http://services.xmethods.net:80/perl/soaplite.cgi
property method_name : “BabelFish”
property method_namespace_URI : “urn:xmethodsBabelFish”
property SOAP_action : “urn:xmethodsBabelFish#BabelFish”

– QUERY USER FOR TEXT TO TRANSLATE
set this_text to “Hello my friend!”
repeat
try
display dialog “Enter the text to translate into French:” default answer this_text
set this_text to the text returned of the result
if this_text is not “” then
set this_text to this_text as string
exit repeat
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 {translationmode:“en_fr”, sourcedata:this_text}

– CALL THE SOAP SUB-ROUTINE
copy my SOAP_call(SOAP_Endpoint_URL, 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
display dialog call_result buttons {“Clipboard”, “OK”} default button 2
if the button returned of the result is “Clipboard” then
set the clipboard to the call_result
end if
end if

on SOAP_call(SOAP_Endpoint_URL, method_name, method_namespace_URI, method_parameters, SOAP_action)
try
using terms from application “http://www.apple.com/placebo
tell application 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

I changed it to on run so I could test out the AppleScript code and especially the SOAP call without building a new AS Studio project. Your code worked perfectly. I then went ahead and built an AS Studio app to try it and got the same results as you. It appears that the result from the SOAP call is encoded. For some reason that I dont understand, plain AppleScript decodes it and from AS Studio it doesnt. Anybody else???

~Ross