Re: Calling an Applescript from Cocoa Java App
Re: Calling an Applescript from Cocoa Java App
- Subject: Re: Calling an Applescript from Cocoa Java App
- From: Ian Gillespie <email@hidden>
- Date: Mon, 14 Jan 2002 15:14:45 -0800
Sorry if my question was not clear. Here is a more step by step
description of what I did.
I have an app that works fine--it builds and runs. I opened up one of
it's nib files in IB and added a button (NSButton) to a window
controlled by that nib file. On the IB Inspector, I selected
AppleScript from the popup menu and then selected the newly added
NSButton on the window. I then checked the "action" checkbox and
"clicked" checkbox under event handlers on the IB Inspector. I then
clicked "New Script" from the IB Inspector and it asked if I wanted to
add the script to my project in PB, I gave it a name (let's call it
aScript) and saved it and the aScript.applescript appeared in project
builder along with my .java files.
Up to this point, I was under the impression that when my button would
be clicked, it would call the script that was just added to project
builder from interface builder. In PB I edited the script to this:
on clicked theObject
tell application "Mail"
end tell
end clicked
The app compiles fine and launches, but when I try to open the window
which has the button on it, I get the error I mentioned above and the
app crashes. Any suggestions?
--__--__--
Message: 10
Date: Mon, 14 Jan 2002 17:19:03 -0500
Subject: Re: Calling an Applescript from Cocoa Java App
From: Bill Cheeseman <email@hidden>
To: Cocoa-Dev Mail <email@hidden>
OK, that I understood. You are using AppleScript Studio, and using it
correctly. The way you set up the button and the Clicked handler are
correct. I just did the same thing in an application I'm working on,
and it
worked as expected.
So, since the error occurs when you open the window, I would look at the
window opening code to see if you have an error there. Perhaps you
should
comment out the Clicked handler and uncheck the Clicked event handler
in the
Info panel, then try building your app and opening the window again. If
the
error still occurs, you'll know it's the window opening code.
The error suggests you haven't loaded the nib file. Usually in a pure
AppleScript Studio app, when you open a window you want your Will Open
handler to call 'load nib "<nib file name without ".nib">"', then call
'set
visible of theObject to true'.
Thanks for the help Bill. It does seem to be the window opening code,
which I had and have none of. Before I added the button and the script
to my project, I had Java code load the nib file and open the window. I
am getting further out of my already small realm of java knowledge, but
I'll ask anyway: should I have the AppleScript code also load the nib
file as you suggested above?