help trouble passing variable

hi. i’m new to applescript and very new to applescript studio. so i apologize in advance if this questions ridiculous. but any help would be seriously appreciated. thanks!!!

anyway so here is my problem. i was writing a script to fetch urls and do some other stuff i do regularly. it is fairly simple script that takes an input from a dialog as a string, processes it and fetches a corresponding url. it worked with an applescript “display dialog” box but i wanted a persistent aqua looking text box. so i built one in applescript studio but i can’t get the input to pass from it to the different functions in my script.

this is how i originally got the string from the user and it worked.


on run
	set commandString to text returned of (display dialog "" default answer "" buttons {"Get"} default button 1)
	getCommand(commandString)
end run

but this is what i tried with applescript studio and it fails at “getCommand(commandString)”


on clicked theObject
	tell window of theObject
		try
			set commandString to contents of text field "commandString" as string
			getCommand(commandString)
		on error
			set contents of text field "commandString" to "bummer"
		end try
	end tell
end clicked

remainder of the script if this helps diagnose the problem.


on getCommand(commandString)
	if commandString is not "" or "quit" then
		if first word of commandString = "google" or "g" then simpleQuery(commandString, "http://www.google.com/search?q=")
		if first word of commandString = "imdb" or "i" then simpleQuery(commandString, "http://www.imdb.com/find?q=")
		if first word of commandString = "map" or "gm" then simpleQuery(commandString, "http://maps.google.com/maps?q=")
		if first word of commandString = "mail" then mail()
		if first word of commandString = "quote" or "q" then simpleQuery(commandString, "http://finance.yahoo.com/q?s=")
		if first word of commandString = "sms" or "s" then sms(commandString)
		if first word of commandString = "tor" then tor(commandString)
		if first word of commandString = "tv" then simpleQuery(commandString, "http://www.tvtome.com/tvtome/servlet/Search?searchType=all&searchString=")
		if first word of commandString = "wiki" or "w" then simpleQuery(commandString, "http://en.wikipedia.org/wiki/Special:Search?search=")
	end if
end getCommand

on simpleQuery(commandString, queryUrl)
	set x to count of words of commandString
	set commandString to (words 2 through x of commandString) as string
	set AppleScript's text item delimiters to " "
	set commandString to every text item in commandString
	set AppleScript's text item delimiters to "+"
	set commandString to every item in commandString as string
	set commandString to queryUrl & commandString as string
	open location commandString
end simpleQuery

on mail()
	open location "http://us.f501.mail.yahoo.com/ym/login"
	open location "http://gmail.google.com/gmail/h/"
end mail

on sms(commandString)
	set commandString to text 3 through length of commandString as string
	set phoneNumber to "&count=&n1=" & first word of commandString & "&n2=" & second word of commandString & "&n3=" & third word of commandString
	set commandString to text 13 through length of commandString as string
	if length of commandString > 120 then set commandString to text 1 through 120 of commandString as string
	set AppleScript's text item delimiters to " "
	set commandString to every text item in commandString
	set AppleScript's text item delimiters to "+"
	set commandString to every item in commandString as string
	set smsUrl to "http://us.rd.yahoo.com/mobile/sendsms_home/*http://mobile.yahoo.com/sms/sendsms?carrier=_none&msg=" & commandString & phoneNumber & "&commit=Send+Message" as string
	open location smsUrl
end sms

on tor(commandString)
	simpleQuery(commandString, "http://www.torrentspy.com/search.asp?query=")
	simpleQuery(commandString, "http://s4.isohunt.com/torrents.php?ihq=")
end tor

on should quit after last window closed theObject
	return true
end should quit after last window closed

thanks again any and all help is appreciated!!!

In a Studio app, when you are inside the scope of an object of the app (basically, a “tell” block), you must target your handlers explicitly, using the “my” keyword.
So, in your code you are inside a “tell window of theobject”, and you should call your handler as “my getCommand(commandString)”.