Receiving Apple Events in a RB app (HandleAppleEvent event) 
Author Message
 Receiving Apple Events in a RB app (HandleAppleEvent event)

I'd like my RB app to be able to receive personnaly-made apple events.

For example I'd like to be able to write in an AppleScript:
tell "MyRBApplication"
     sayHello
end tell

What do I need to write in the HandleAppleEvent event of my
MyRBApplication  RB application?
I see that the event gives me access to the parameters of the apple
event received, ok.
But I don't know how to tell (to the Finder maybe?) that my RB
application is able to receive the "sayHello" parameter.

What do I have to do to make the above AppleScript accepted by the
Finder and sent to MyRBApplication?
What do I have to write in my HandleAppleEvent event to handle this
event (and recognize it) when my RB application receives it?

There is nothing explained in details in RB documentation.

PS: I can't find anymore the RB examples that were available a few
months ago on RB FTP site... do they still exist?

Remark not important: This message above in facts would help me for
example to make 2 RB application communicate together by the mean of
AppleEvents (and not sockets for example)...

Thanks,
Pascal.



Mon, 24 Oct 2005 01:53:28 GMT  
 Receiving Apple Events in a RB app (HandleAppleEvent event)

Quote:

> But I don't know how to tell (to the Finder maybe?) that my RB
> application is able to receive the "sayHello" parameter.

Write an "aete" resource.
Resedit may help with an aete editor extension.

Mfg
Christian

--
Four thousand functions in one REALbasic plug-in. The MBS Plugin.

<http://www.monkeybreadsoftware.de/realbasic/plugins.html>



Mon, 24 Oct 2005 02:21:30 GMT  
 Receiving Apple Events in a RB app (HandleAppleEvent event)

Quote:

> I'd like my RB app to be able to receive personnaly-made apple events.

> For example I'd like to be able to write in an AppleScript:
> tell "MyRBApplication"
>      sayHello
> end tell

This is not a trivial problem, but you can find an moderately detailed
discussion of the solution in REALbasic Developer.  In Advanced
Techniques in the last issue (issue 1.5), I wrote about the basics of
creating an AppleScriptable app.  In the next issue, Advanced
Techniques will discuss more advanced aspects of this process.  You may
want to consider a subscription -- it's chock-full of goodness, anyway.

<http://www.rbdeveloper.com/>

Here's the basic idea, though.  In order to have your app be
scriptable, you need first to create an 'aete' resource.  For this, you
can use something like Resourcerer (which is commercial and expensive,
Google it) or EightyRez (free, but Classic only,
<http://www.panix.com/~gmcgath/EightyRez.html>).  You'll also need to
know a bit about what you're doing.

Next, you've got to write code in HandleAppleEvent that properly
handles the event.  For a script like 'sayHello', this would be pretty
simple.  For scripts like 'set field 3 of window named "world" to
"hello"', this gets pretty darn complex.  (In fact, that one aspect of
handling scripting is almost the entirety of the next Advanced
Techniques column.)

I can't recommend highly enough that you read Apple's Inside Macintosh:
Interapplication Communication.  It's freely available and is a VERY
complete reference to AppleEvent handling, including info about
AppleScriptable applications.  This will help you figure out how an
'aete' works, how events are constructed and interpreted, etc.

<http://developer.apple.com/techpubs/mac/IAC/IAC-2.html>

Also, to see an example of an AppleScriptable app, check out my free
and open-source App Bundler program:

<http://home.earthlink.net/~thomasareed/shareware/>

Good luck!



Mon, 24 Oct 2005 02:40:41 GMT  
 Receiving Apple Events in a RB app (HandleAppleEvent event)
So in fact you mean that the HandleAppleEvent in RB makes people
believe they can receive (easily) apple event whereas in fact it is
not obvious!

If I have to edit the ressources of my application (with a Res
Editor), each time I rebuild my app I have to remodify it?
It mean that it is impossible to receive custom apple events when you
run your app from the IDE?
That's incredible...

I'm sad... :'(

There is really not way only with RB code to be able to receive a
simple custom event (like sayHello)? :'(

A+
Pascal.



Mon, 24 Oct 2005 15:51:38 GMT  
 Receiving Apple Events in a RB app (HandleAppleEvent event)

Quote:
>If I have to edit the ressources of my application (with a Res
>Editor), each time I rebuild my app I have to remodify it?

No, no. You can simply put the aete-resource into a resourcefile named
resources (or was it resource?) and drop that into the RB project. So
it will be build automatically into your application.

Quote:
>It mean that it is impossible to receive custom apple events when you
>run your app from the IDE?
>That's incredible...

With RB < 5.0 this is correct, but with >= 5.0 this is no longer
correct.

Quote:
>There is really not way only with RB code to be able to receive a
>simple custom event (like sayHello)? :'(

No, because AppleScript doesn't know which AppleEvent it should send
to you.

Carsten



Mon, 24 Oct 2005 16:10:53 GMT  
 Receiving Apple Events in a RB app (HandleAppleEvent event)

Quote:

> So in fact you mean that the HandleAppleEvent in RB makes people
> believe they can receive (easily) apple event whereas in fact it is
> not obvious!

First, you *can* easily receive an AppleEvent.  AppleEvents and
AppleScripts are two different things.  AppleEvents are the mechanism
behind AppleScript, but AppleScript also involves interpretation of the
script code.  In order to map particular words in your script to
AppleEvents, you must provide an 'aete' resource.  If you don't care
about scriptability, you can still handle AppleEvents to your heart's
content.

Second, you make it sound like RS is deceiving people by not making it
easier to handle AppleEvents.  In fact, they've done a substantial
amount of the work for you.  The fact that there's a considerable
amount more to be done by you is simply a fact of life.  Handling
AppleEvents is not a trivial task.  You don't get upset about not being
able to sit down and crank out a web server using the Socket class
without knowledge of internet communications, do you?

Quote:
> If I have to edit the ressources of my application (with a Res
> Editor), each time I rebuild my app I have to remodify it?

No, just add a resource file containing your 'aete' to the project.

Quote:
> It mean that it is impossible to receive custom apple events when you
> run your app from the IDE?

Unless you're using RB 5.x, that is true, unfortunately.  However, in
RB 5.x, this is a thing of the past.

Quote:
> There is really not way only with RB code to be able to receive a
> simple custom event (like sayHello)? :'(

Get a copy of issue 1.5 of REALbasic Developer.  The Advanced
Techniques column will tell you everything you need to know to do this
very thing.

--
-Thomas

e-mail me at thomasareed at <insert home planet> + link.net



Tue, 25 Oct 2005 02:12:25 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to RECEIVE a custom apple event?

2. Only One Tkinter Entry can receive key event event in Linux RH8.0

3. Tcl Event Loop vs TK Event Loop issues with Asynchronous Events

4. How to receive MSHTML events?

5. Open event not received

6. Receiving Events from Outlook

7. Cannot receive ActiveX Controls Events in LV

8. Receiving a COM event from a DLL in LabView

9. Doesn't receive any ActiveX events from COM-server

10. MZScheme on Mac...receiving Events?

11. pythoncom: STA python COM server randomly does not receive event from other objects : deadlock

12. LispView RECEIVE-EVENT

 

 
Powered by phpBB® Forum Software