I have two processes that communicate using apple events. The first app is an electron nodejs app. The other one is a shim bundle attached to Microsoft Word that allows the user to insert OLE objects generated by my app. The shim has been developed in objective-c. When the user inserts an object in Microsoft Word, the shim calls my app and shows the object in a new window. The user can edit the object and save it. When the user saves the object, the app sends an Apple Event to Microsoft Word with the object information; the shim receives this information and inserts the object modified. The code in charge of this communication in both sides is:
App side (programmed in objective-c++ as a native module of nodejs app)
NSAppleEventDescriptor *aeEvent = [NSAppleEventDescriptor
appleEventWithEventClass:kCustomCoreEventClass // 'core'
eventID:kAEEGOSetData // 'setd'
targetDescriptor:clientAddressDesc
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
//.... some more code to set important information ....
//set data if it has changed
if(dataChanged) {
NSAppleEventDescriptor * imageDataDesc = [NSAppleEventDescriptor
descriptorWithDescriptorType:dataType
bytes:[data bytes] //NSData object containing data to send
length:[data length]];
[aeEvent setDescriptor:imageDataDesc
forKeyword:kKeyEGOData];
}
//send event and free memory
AppleEvent reply;
AESendMessage([aeEvent aeDesc], &reply, kAEWaitReply, kAEDefaultTimeout);
Shim side (programmed in objective-c++)
- (void)handleAppleEvent:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
//.... do some work with the event information....
NSAppleEventDescriptor *imageData = [event paramDescriptorForKeyword:kDataKeyWord];
//...keep working using the data obtained....
}
which has been previously installed using:
[appleEventManager setEventHandler:self
andSelector:@selector(handleAppleEvent:withReplyEvent:)
forEventClass:kAECoreSuite // 'core'
andEventID:kAESetData]; // 'setd'
In the past, we treated differently information received from word and information received from other apps (such as Pages). For this reason, the keyword kKeyEGOData, which matches kDataKeyWord had been set to 'ShmD', while the interactions with other apps used the keyword 'data'. However, now we have unified both codes. The app behaves equally when receiving information from Word than the rest of the apps. For this reason, we wish to change thes keywords to 'data'. The problem that I have is that when sending the event using the word 'data' instead of 'ShmD', the word app does not enter the handler function, even if kDataKeyWord has been set to 'data'. Why could this possibly happen?
Edit:
I have tried the exchange launching Microsoft Word with debugging activated. Here I attach the logs printed in the terminal related to these apple events:
Send an event with 'ShmD' keyword to store the data:
{core,setd target=myApp {Uniq=*****,----=obj (****),data=**** (***...)} returnID=****}
#################### handleAppleEvent
Where '#################### handleAppleEvent' is printed by 'printf()' at the beginning of the handle function. Therefore, the app receives the event with the data correctly set and enters the handle function.
Send an event with 'data' keyword to store the data:
{core,setd target=myApp {Uniq=*****,----=obj (****),data=**** (***...)} returnID=****}
The event is correctly detected by Microsoft Word but it never reaches the handler.
It does not matter in which order I send the events, the behavour is consistent. That is:
- if I send an event with keyword 'data' it NEVER reaches the handler, even when preceeded by an event with data keyword 'ShmD'.
- If I send an event with keyword 'ShmD' it ALWAYS reaches the handler, even when preceeded by an event with data keyword 'data'.