I am working on C application which uses AppleEvents. So far I am trying to do simple example which sends Activate to the Terminal. This is what I have:
int main()
{
AppleEvent theEvent;
char* arg = "com.apple.Terminal";
AEAddressDesc addDesc;
OSErr err = AECreateDesc( typeApplicationBundleID, &arg, strlen( arg ), &addDesc );
printf("AECreateDesc error --> %d\n", err);
if( noErr == err )
{
// my event creation
// create event:
err = AECreateAppleEvent( 'misc', 'actv', &addDesc, kAutoGenerateReturnID, kAnyTransactionID, &theEvent );
}
printf("AECreateAppleEvent error --> %d\n", err);
if (noErr == err)
{
AESendMode aeSendMode = kAEAlwaysInteract | kAEWaitReply;
//err = AESend( &theEvent, NULL, aeSendMode, kAENormalPriority, kAEDefaultTimeout, NULL, NULL );
err = AESendMessage(&theEvent, NULL, aeSendMode, kAEDefaultTimeout);
}
printf("AESend error --> %d\n", err);
return 0;
}
But when I run the program it always prints AESend error --> -600 which I have seen that means process not found
Could someone tell me what is wrong here please?
Note: I do not want to use AppleScript, I want to use this, so please no recommendations about using AppleScript
Thanks in advance and regards
You should call:
OSErr err = AECreateDesc( typeApplicationBundleID, arg, strlen( arg ), &addDesc );
without &
.