Managing AppleEvents

Hi all
I don’t understand how to manage AppleEvent with Xojo : I mean creating AE in one app for a targetApp :
Var a As AppleEvent = New AppleEvent("zoz1", "whte", "")

and receiving it in an other app with the HandleAppleEvent App’s event.

I don’t understand how and where to record AE.
Thanks for any help…

I’m interested too, if anyone has any info…

Thomas Tempelmann has a complete framework for supporting AppleScript in Xojo apps. See Thomas Tempelmann | Making your Xojo OS X application scriptable (AppleScript) .

1 Like

Have you tryed the documentation ?

cmd-k appleevent returns:

Thanks Beatrix.

The TT code works fine with AppleScript, but not with direct AppleEvent calls :

Var a As AppleEvent = New AppleEvent(“AEts”, “MkUp”, “org.tempel.test.aetest”)
If Not a.Send Then MessageBox(“The AppleEvent could not be sent.”)

####—> The AE is sent to the app (no error) but the HandleAppleEvent isn’t called.

Var b As AppleEvent
b = New AppleEvent(“aevt”, “odoc”, “org.tempel.test.aetest”)
If Not b.Send Then MessageBox(“The AppleEvent could not be sent.”)

####—> The AE is sent to the app (no error) AND the HandleAppleEvent is called.

I believe that the EventClass and EventID have to be defined somewhere. I haven’t seen anything like that in Xojo doc and Apple’s doc.
A workaround is to use AppelScript, but that’s strange to use AppleScript when we can use AppleEvent directly.

What you’ve got should work in principle. Modern versions of Mac OS require an entitlement in your info.plist to allow your app to send Apple Events to other apps. This is an important security measure, even though it can be rather annoying to comply with.

The reason your ‘odoc’ Apple Event works is that the open document event isn’t filtered by the security system, while your custom “AEts” event is.

The solution is that you need to tell the OS you intend to use Apple Events by including a key/value pair in your application’s info.plist file. Check out this prior discussion:

1 Like

If you’re wanting to react to a custom URI, the main point of interest in my post that Eric mentioned would probably be this blog post from Javier Menendez:

The issue I ran into was mixing plist entries both manually and with PLIstBuddy. Despite the plist having what appeared to be the correct contents, Apple security ignored it. Creating the entire plist either manually or via PListBuddy worked.

Thanks Scott !!!
It’s the good answer !
Now I can send AE to an other APP !