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.
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.
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?
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.
– Rob (who isn’t qualified to answer AppleScript Studio/Interface Builder questions)
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
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.
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)
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:
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)…