Re: Invoking an Objective-C method from an Applescript
Re: Invoking an Objective-C method from an Applescript
- Subject: Re: Invoking an Objective-C method from an Applescript
- From: Robert MacGregor <email@hidden>
- Date: Mon, 22 Aug 2005 18:26:12 -0400
On 22-Aug-05, at 4:04 PM, Christopher Nebel wrote:
On Aug 22, 2005, at 9:01 AM, Robert MacGregor wrote:
I'm trying to invoke an Objective-C method from a Java method
within my app using NSAppleScript.:
Let me see if I've got this right: you've built a Cocoa-Java
application, and you're trying to trigger a method in it from
another application using AppleScript (more precisely, calling
NSAppleScript to run a script)? Suppressing any comments about how
Byzantine this sounds...
You got it! :-) It is Byzantine but it's done for a reason; I'm using
a Java socket for inter-application communication. I wanted an
AppleScript Studio app for it's ease of coding and UI and, in the
background, Java apps to handle networking. Communication between UI
and background apps also uses Java sockets.
My UI app started life as a Cocoa/Java app to obtain Java build
rules. I added Applescript and linked-in the AppleScriptKit; my app
has the standard suite sdef file in it's bundle.
My Java socket blocks waiting for data and this causes my UI to
become unresponsive. My solution creates a separate Java-thread for
the blocking socket and returns immediately to permit UI processing
(in this case Applescript processing). The odd script-calling-back-
into-the-UI behavior occurs when the socket has data and sends a
message to the UI to update.
I tried providing a method in my UI app to act as a callback but I
couldn't expose it via the sdef mechanism because of my lack of
expertise with sdef. :-( This prompted the email about Objective-C.
I settled on using/abusing an existing Applescript command to convey
data into my Applescript UI. I use 'open "text-string" and provide an
open-handler in my UI to process my string data; it works. :-) I
tried using other commands and found the command didn't reach my
app's handler; presumably intercepted by an up-stream handler. I
realize there is a conflict of 'open's' use but I can live with it
for now.
If you have suggestions about exposing Applescript methods to other
applications I'd be interested to hear them.
Thanks for the information about 'call method'.
Rob
"call method" is only defined in applications that link to
AppleScriptKit. (There's some Cocoa Scripting magic that happens
when you do that.) An AppleScript Studio application does this
implicitly; that's part of what using AppleScript Studio means.
Other applications don't, so you'll have to add it manually to your
Cocoa-Java app. (Actually, I'm not sure that it's that quite that
simple -- there may be a method you need to invoke at startup.)
--Chris Nebel
AppleScript and Automator Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden