Coding Apple Events

121 Views Asked by At

I have an very simple AppleScript:

tell application "Opera"
   get URL of active tab of window 1
end tell

This is the translation to AppleEvents:

osascript browser.scpt 
{core,getd target='psn '[Opera] {----={form=prop,want=prop,seld=URL ,from={form=prop,want=prop,seld=acTa,from={form=indx,want=cwin,seld=1,from=NULL-impl}}}} attr:{csig=65536 returnID=15130}

For some reasons I cannot use AppleScript so I need to translate those events into C code.

So far I have this after looking at some examples and reading some doc:

AppleEvent theEvent;
AEIdleUPP theIdleProc = NewAEIdleUPP((AEIdleProcPtr)&TheIdleFunction );
if( NULL != theIdleProc )
{
    char* arg = "Opera";
    AEAddressDesc addDesc;
    err = AECreateDesc( typeProcessSerialNumber, &arg, sizeof( arg ), &addDesc );
    printf("AECreateDesc error --> %d\n", err);
    if( noErr == err )
    {
        // my event creation
        // create event:
        err = AECreateAppleEvent( 'core', 'getd', &addDesc, kAutoGenerateReturnID, kAnyTransactionID, &theEvent );
        // create descriptors needed
        AEDesc indexDescriptor;
        long indexVerb = 'indx';
        err = AECreateDesc('enum',&indexVerb,4,&indexDescriptor);
        AEDesc nullDsc;
        err = AECreateDesc(typeNull, nil, 0, &nullDsc);
        //seld = 1
        long seldIndex = 1;
        AEDesc seldIndexDesc;
        err = AECreateDesc(typeSInt64 ,&seldIndex,4,&seldIndexDesc);
        err = CreateObjSpecifier('cwin',&nullDsc,'ID  ',&theSeldDesc,true,&theThirdObjSpec);
    }
}
    return 0;

But I am kind of stuck here. How do I connect "form=indx" for example to "want=cwin" Do I need to create AEDesc for form part, then for want part and also for seld?

Also what is the meaning of last line in raw event? "attr:{csig=65536 returnID=15130}"

I am kind of lost with this. I would appreciate small example to use as guide

Thanks in advance

0

There are 0 best solutions below