0

So with CTypes Im tryng to convert this code below. It uses OSType, OSType is dfined as

FourCharCode = ctypes.c_uint32
OSType = FourCharCode
QTPropertyClass = OSType

We see here it is an usngiend character. But We see in snippet below they defined it as

const OSType    kFinderSig = 'MACS';

So in ctypes, setting a variable to 'MACS' would not e c_uint32 type but it will be char no?

Please advise.

Thanks

https://stackoverflow.com/a/8895297/1828637

OSStatus    SendFinderSyncEvent( const FSRef* inObjectRef )
{
    AppleEvent  theEvent = { typeNull, NULL };
    AppleEvent  replyEvent = { typeNull, NULL };
    AliasHandle itemAlias = NULL;
    const OSType    kFinderSig = 'MACS';

    OSStatus    err = FSNewAliasMinimal( inObjectRef, &itemAlias );
    if (err == noErr)
    {
        err = AEBuildAppleEvent( kAEFinderSuite, kAESync, typeApplSignature,
            &kFinderSig, sizeof(OSType), kAutoGenerateReturnID,
            kAnyTransactionID, &theEvent, NULL, "'----':alis(@@)", itemAlias );

        if (err == noErr)
        {
            err = AESendMessage( &theEvent, &replyEvent, kAENoReply,
                kAEDefaultTimeout );

            AEDisposeDesc( &replyEvent );
            AEDisposeDesc( &theEvent );
        }

        DisposeHandle( (Handle)itemAlias );
    }

    return err;
}
Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

2
const OSType    kFinderSig = 'MACS';

'MACS' is a character constant, not a string! This code is using a (questionable) GCC extension for multi-character character constants.

You can reproduce the results in Python using the (builtin) struct module:

import struct
kFinderSig = struct.unpack(">L", "MACS")[0]

Alternatively, just hard-code the value as 0x4d414353 and leave a comment that it represents "MACS".

Community
  • 1
  • 1
  • Thank you a thousand times!! This was driving me nuts!! A special thank you for two solutions in one! I love learning from seeing different ways doing the same thing, that helps a ton!! – Noitidart Jan 13 '15 at 04:38
  • 1
    In Python 3 you can also use `kFinderSig = int.from_bytes(b'MACS', 'big')`. ctypes data types aren't as convenient here due to the big-endian requirement: `kFinderSig = c_uint32.__ctype_be__.from_buffer_copy(b'MACS')`. – Eryk Sun Jan 13 '15 at 15:22