Help With My First Script

I am still in the process of trying to get my first program working.
First off, here is my current code:


on clicked theObject
	if the name of theObject is equal to "addGame" then
		using terms from application "iCal"
			tell application "iCal"
				activate
				set paracal to (first calendar whose title is "Games & DVDs")
				make new event at end of events of paracal with properties {summary:gameTitle, location:gameSystem, description:gameNotes, date:releaseDate}
				set new_event to result
				tell new_event
					make new display alarm at end of display alarms with properties {trigger interval:0}
				end tell
			end tell
		end using terms from
	else if the name of theObject is equal to "resetForm" then
	end if
	
end clicked

Issues I am having:
clicking on my “addGame” button returns:
AppleScript Error: The variable gameTitle is not defined. (-2753)

My “resetForm” button… well, I don’t know how to make that work. Is there AppleScript for it or is there just a universal command like an HTML reset button?

I have a little spinning indicator. How do I “hook that up” so it works? I am sure I have to do more then just dump in into my UI.

Will somone out there lend me a hand?

Thanks,
Abraham[/b]

Well I have started from scratch on my AppleScript building one line at a time… making things beep, launch, quit, etc so I can get a feel for it a bit.

I am finally back to a modified version of the code above:


on clicked theObject
	
	if the name of theObject is equal to "addGame" then
		using terms from application "iCal"
			tell application "iCal"
				activate --to launch iCal
				set paracal to (first calendar whose title is "Games & DVDs")
				make new event at end of events of paracal with properties {summary:gameTitle, location:gameSystem, description:gameNotes, start date:releaseDate}
				set new_event to result
			end tell
		end using terms from
	else if the name of theObject is equal to "resetForm" then
		set contents of text fields of theWindow to ""
		beep
	end if
	
end clicked

But alas, my “variables still aren’t defined” when I run my program!
Aren’t the defined in my UI? I have scoured the internet for hours upon hours trying to figure out what that means and how to fix it. :frowning:

If I have a text field in my UI (Interface Builder) and the AppleScript name of it is “gameTitle”, why won’t it work in my script?

Anyone… please…

You might have a better chance of getting help if you ask for help in the AppleScript Studio forum. If you contact one of the BBS admins, they might move this thread to the proper forum. :slight_smile:

– Rob (who isn’t qualified to answer AppleScript Studio/Interface Builder questions)

You need to refer to one of the properties of your text field, instead of using its name, such as:

set gameTitle to contents of text field "gameTitle" of window "main"

(btw, thanks, Rob, I’ll move this one to its location) :wink:

jj -

Thanks for the help. I switched my code to as it is shown below but I am still getting that unknown varialbe error:


set gameTitle to contents of text field "gameTitle" of window "theWindow"
set gameSystem to contents of text field "gameSystem" of window "theWindow"
set gameNotes to contents of text field "gameNotes" of window "theWindow"
set releaseDate to contents of text field "releaseDate" of window "theWindow"

on clicked theObject
	
	if the name of theObject is equal to "addGame" then
		using terms from application "iCal"
			tell application "iCal"
				activate --to launch iCal
				set paracal to (first calendar whose title is "Games & DVDs")
				make new event at end of events of paracal with properties {summary:gameTitle, location:gameSystem, description:gameNotes, start date:releaseDate}
				set new_event to result
			end tell
		end using terms from
	else if the name of theObject is equal to "resetForm" then
		set contents of text fields of theWindow to ""
		beep
	end if
	
end clicked

Any ideas?

You must define the variables inside the handler “clicked”, otherwise it won’t know about them. Eg:

You may take a look to the concept of “variable scope”:
http://macscripter.net/faq/general.php?id=P184

jj -

moved that code snippet inside the onclick and am now getting:
NSReceiverEvaluationScriptError: 4 (1)

I read that page last night in my searching but have printed it off and will take it with me so I can study it a bit more. Thanks again for all your help. :smiley:

Then, perhaps any text field is not named as you say it’s named, or they don’t reside in a window called “theWindow” :?:
Try before:
log contents of…
And watch the output in the log window… (use Build & Run to see the results of your “log” commands)


	if the name of theObject is equal to "addGame" then

  1. It shouldn’t matter, but does name of theObject as string work any differently? (I’m unable to check this atm.)

	else if the name of theObject is equal to "resetForm" then
		set contents of text fields of [b]theWindow[/b] to ""
		beep
	end if

  1. In “of theWindow”, theWindow is being used as a variable (which is undefined). I think you meant:

set contents of text fields of [b]window "theWindow"[/b] to ""

Edit: Typo.
Are we not allowed to use HTML here?

I just can’t figure it out. :frowning:

I have spent more time (days) on this little hobby project then I can afford. I know this is REAL basic stuff for some of you so I am hoping someone out there can help.

I am posting a .zip file of my XCode project. I hope that is cool to do on this board. If anyone has some free time and can help me out, here is the file:

http://apps.dizandat.com/files/GameTrackerRemote.zip

Again, thanks for the help you guys. :slight_smile:

Now is it! A classical puzzle:

set gameTitle to contents of text field "gameTitle" of  box 1 of window "theWindow"

:lol:

I changed that line in the applescript and am getting this error:

NSReceiverEvaluationScriptError: 4 (1)

Have you changes all other text fields? Seems that they all are inside a “box”…

This is my applescript code as of now… still getting that same error above:


on clicked theObject
	
	set gameTitle to contents of text field "gameTitle" of box 1 of window "theWindow"
	set gameSystem to contents of text field "gameSystem" of box 1 of window "theWindow"
	set gameNotes to contents of text field "gameNotes" of box 1 of window "theWindow"
	set releaseDate to contents of text field "releaseDate" of box 1 of window "theWindow"
	
	if the name of theObject is equal to "addGame" then
		using terms from application "iCal"
			tell application "iCal"
				activate --to launch iCal
				set paracal to (first calendar whose title is "Games & DVDs")
				make new event at end of events of paracal with properties {summary:gameTitle, location:gameSystem, description:gameNotes, start date:releaseDate}
				set new_event to result
			end tell
		end using terms from
	else if the name of theObject is equal to "resetForm" then
		set contents of text fields of window "theWindow" to ""
		beep
	end if
	
end clicked

OK. “gameNotes” is not a text field, but a text view inside of a scroll view:

	set gameTitle to contents of text field "gameTitle" of box 1 of window "theWindow"
	set gameSystem to contents of text field "gameSystem" of box 1 of window "theWindow"
	set gameNotes to contents of text field "releaseDate" of box 1 of window "theWindow"
	set releaseDate to contents of text view 1 of scroll view "gameNotes" of box 1 of window "theWindow"

display dialog "All was fine till here!"

Now, I never scripted iCal, but it seems that it won’t accept text for its parameter “start date”, but an applescript date? (but this is a topic for another question)…