static OSStatus SendEventToSystemEventsWithParameters(AEEventClass theClass, AEEventID theEvent, AppleEvent *reply, ...) { OSStatus err; ProcessSerialNumber psn; AppleEvent event = WBAEEmptyDesc(); AppleEvent target = WBAEEmptyDesc(); AppleEvent localReply = WBAEEmptyDesc(); check( (reply == NULL) || (reply->descriptorType == typeNull) ); // Create Apple event. err = WBFindSystemEvents(&psn); if (err == noErr) { err = WBAECreateEventWithTargetProcess(&psn, theClass, theEvent, &event); } // if (noErr == err) // err = WBAESetStandardAttributes(&event); // Handle varargs parameters. if (err == noErr) { va_list ap; AEKeyword thisKeyword; const AEDesc * thisDesc; va_start(ap, reply); do { thisKeyword = va_arg(ap, AEKeyword); if (thisKeyword != 0) { thisDesc = va_arg(ap, const AEDesc *); check(thisDesc != NULL); err = AEPutParamDesc(&event, thisKeyword, thisDesc); } } while ( (err == noErr) && (thisKeyword != 0) ); va_end(ap); }
OSErr putMissingValueToReply(AppleEvent *reply) { const static DescType missingValue = cMissingValue; OSErr err; AEDesc resultDesc; AECreateDesc(typeType, &missingValue, sizeof(missingValue), &resultDesc); err=AEPutParamDesc(reply, keyAEResult, &resultDesc); AEDisposeDesc(&resultDesc); return err; }
OSStatus SendOpenAE( AEDescList list ) { OSStatus err; AEAddressDesc theAddress; AppleEvent dummyReply; AppleEvent theEvent; theAddress.descriptorType = typeNull; theAddress.dataHandle = NULL; dummyReply.descriptorType = typeNull; dummyReply.dataHandle = NULL; theEvent.descriptorType = typeNull; theEvent.dataHandle = NULL; do { ProcessSerialNumber psn; err = GetCurrentProcess(&psn); if ( err != noErr) break; err =AECreateDesc(typeProcessSerialNumber, &psn, sizeof(ProcessSerialNumber), &theAddress); if ( err != noErr) break; err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &theEvent); if ( err != noErr) break; err = AEPutParamDesc(&theEvent, keyDirectObject, &list); if ( err != noErr) break; err = AESend(&theEvent, &dummyReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); if ( err != noErr) break; } while (false); if ( theAddress.dataHandle != NULL ) { AEDisposeDesc( &theAddress ); } if ( dummyReply.dataHandle != NULL ) { AEDisposeDesc( &dummyReply ); } if ( theEvent.dataHandle != NULL ) { AEDisposeDesc( &theEvent ); } return err; }
OSErr putAliasToReply(AliasHandle inAlias, AppleEvent *reply) { OSErr err; AEDesc resultDesc; HLock((Handle)inAlias); err = AECreateDesc(typeAlias, (Ptr) (*inAlias), GetHandleSize((Handle) inAlias), &resultDesc); HUnlock((Handle)inAlias); err=AEPutParamDesc(reply, keyAEResult, &resultDesc); AEDisposeDesc(&resultDesc); return err; }
// DestoryWacomContext // // This function will instruct the Tablet Driver to delete a context that your // application created. Please be nice and destroy all contexts you create // before your application quits. // // parameters: UInt32 contextID - The ID returned to you when you created the // context. // // returns: a contextID and noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr DestoryWacomContext(UInt32 contextID) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; AppleEvent aeSend; OSErr err; err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAEDelete, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to destroy //Create NULL AEDesc, this will signify the end of the AEDesc Chain AEInitializeDesc(&nullDesc); err = AECreateDesc( typeNull, NULL, NULL, &nullDesc ); AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &contextID, // This is the context ID we want to destroy sizeof(contextID), &keyData ); err = CreateObjSpecifier(cContext, // We want to destroy a context &nullDesc, // This is the last item in the chain formUniqueID, // use id to determine which context to destroy &keyData, // This is the Context ID descriptor created above TRUE, // delete the nullDesc, and KeyData descriptor for us &tObjSpecifier); // The created descriptor which says that we want to delete Context X err = AEPutParamDesc( &aeSend, keyDirectObject, &tObjSpecifier); // Finally send the event err = AESend(&aeSend, // The complete AE we created above NULL, // Don't need a reply kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend);
void Moose::launchAudioscrobbler( const std::vector<std::string>& vargs ) { FSRef appRef; LSFindApplicationForInfo( kLSUnknownCreator, CFSTR( AUDIOSCROBBLER_BUNDLEID ), NULL, &appRef, NULL ); const void* arg[vargs.size()]; int index(0); AEDescList argAEList; AECreateList( NULL, 0, FALSE, &argAEList ); for( std::vector<std::string>::const_iterator i = vargs.begin(); i != vargs.end(); i++ ) { arg[index++] = CFStringCreateWithCString( NULL, i->c_str(), kCFStringEncodingUTF8 ); AEPutPtr( &argAEList, 0, typeChar, i->c_str(), i->length()); } LSApplicationParameters params; params.version = 0; params.flags = kLSLaunchAndHide | kLSLaunchDontSwitch | kLSLaunchAsync;; params.application = &appRef; params.asyncLaunchRefCon = NULL; params.environment = NULL; CFArrayRef args = CFArrayCreate( NULL, ((const void**)arg), vargs.size(), NULL); params.argv = args; AEAddressDesc target; AECreateDesc( typeApplicationBundleID, CFSTR( AUDIOSCROBBLER_BUNDLEID ), 16, &target); AppleEvent event; AECreateAppleEvent ( kCoreEventClass, kAEReopenApplication , &target, kAutoGenerateReturnID, kAnyTransactionID, &event ); AEPutParamDesc( &event, keyAEPropData, &argAEList ); params.initialEvent = &event; LSOpenApplication( ¶ms, NULL ); AEDisposeDesc( &argAEList ); AEDisposeDesc( &target ); }
OSErr putBoolToReply(Boolean aBool, AppleEvent *reply) { #if useLog printf("start putBoolToReply\n"); #endif OSErr err; DescType resultType = (aBool? typeTrue:typeFalse); AEDesc resultDesc; AECreateDesc(resultType, NULL, 0, &resultDesc); err=AEPutParamDesc(reply, keyAEResult, &resultDesc); AEDisposeDesc(&resultDesc); #if useLog printf("end putBoolToReply\n"); #endif return err; }
OSErr putBooleanToEvent(AppleEvent *ev, AEKeyword keyword, Boolean inBool) { #if useLog fputs("start putBooleanToEvent", stderr); #endif OSErr err; DescType resultType = (inBool? typeTrue:typeFalse); AEDesc resultDesc; AECreateDesc(resultType, NULL, 0, &resultDesc); err = AEPutParamDesc(ev, keyword, &resultDesc); AEDisposeDesc(&resultDesc); #if useLog fputs("end putBooleanToEvent", stderr); #endif return err; }
OSErr putFileURLToEvent(AppleEvent *ev, AEKeyword keyword, CFURLRef inURL) { #if useLog fputs("start putFileURLToEvent", stderr); #endif OSErr err; AEDesc resultDesc; err = AEDescCreateWithCFURL(inURL, &resultDesc); if (err != noErr) goto bail; err = AEPutParamDesc(ev, keyword, &resultDesc); AEDisposeDesc(&resultDesc); bail: #if useLog fputs("end putFileURLToEvent", stderr); #endif return err; }
static VALUE __rbosa_insertion_loc_new (VALUE rcv, FourCharCode code) { AEDesc * self_desc; AEDesc rec; AEDesc pos_desc; AEDesc new_desc; self_desc = rbosa_element_aedesc (rcv); AECreateList (NULL, 0, true, &rec); AEPutParamDesc (&rec, keyAEObject, self_desc); AECreateDesc (code, NULL, 0, &pos_desc); AEPutParamPtr (&rec, keyAEPosition, typeEnumerated, &pos_desc, 4); AECoerceDesc (&rec, typeInsertionLoc, &new_desc); AEDisposeDesc (&rec); return rbosa_element_make (cOSAElement, &new_desc, Qnil); }
OSErr putStringToEvent(AppleEvent *ev, AEKeyword keyword, CFStringRef inStr, CFStringEncoding kEncoding) { #if useLog fputs("start putStringToEvent", stderr); #endif OSErr err; AEDesc resultDesc; err = AEDescCreateWithCFString(inStr, kEncoding, &resultDesc); if (err != noErr) goto bail; err = AEPutParamDesc(ev, keyword, &resultDesc); AEDisposeDesc(&resultDesc); bail: #if useLog fputs("end putStringToEvent", stderr); #endif return err; }
static PyObject *AEDesc_AEPutParamDesc(AEDescObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; AEKeyword theAEKeyword; AEDesc theAEDesc; if (!PyArg_ParseTuple(_args, "O&O&", AE_GetOSType, &theAEKeyword, AE_AEDesc_Convert, &theAEDesc)) return NULL; _err = AEPutParamDesc(&_self->ob_itself, theAEKeyword, &theAEDesc); if (_err != noErr) return AE_MacOSError(_err); Py_INCREF(Py_None); _res = Py_None; return _res; }
OSErr putFilePathToReply(CFURLRef inURL, AppleEvent *reply) { OSErr err; char buffer[bufferSize]; CFURLGetFileSystemRepresentation(inURL, true, (UInt8 *)buffer, bufferSize); AEDesc resultDesc; err=AECreateDesc(typeUTF8Text, buffer, strlen(buffer), &resultDesc); if (err != noErr) goto bail; err=AEPutParamDesc(reply, keyAEResult, &resultDesc); //if (err != noErr) { AEDisposeDesc(&resultDesc); //} bail: return err; }
OSErr putStringListToEvent(AppleEvent *ev, AEKeyword keyword, CFArrayRef array, CFStringEncoding kEncoding) { OSErr err; AEDescList resultList; err = AECreateList(NULL, 0, FALSE, &resultList); for (int n = 0; n < CFArrayGetCount(array); n++) { CFStringRef string = CFArrayGetValueAtIndex(array, n); AEDesc string_desc; err = AEDescCreateWithCFString(string, kEncoding, &string_desc); if (err != noErr) goto bail; err = AEPutDesc(&resultList, n+1, &string_desc); AEDisposeDesc(&string_desc); } err = AEPutParamDesc(ev, keyword, &resultList); bail: AEDisposeDesc(&resultList); return err; }
OSErr SetData_ofSize_ofType_ofTabletObject_ForAttribute(void *inDataPtr, Size inDataSize, DescType dataType, TAEObject *pTabletObject, DescType attribute) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; AEDesc lastDesc; AppleEvent aeSend; UInt32 tmpIndex = 0; OSErr err; // assert(inDataPtr); if(!inDataPtr) { return -1; } err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAESetData, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to set // We have to set up a chain here. // Attribute -> Button -> Transducer -> Application -> Tablet -> null // The thing is, Apple Events are built backwards. So... //Create NULL AEDesc, this will signify the end of the AEDesc Chain AEInitializeDesc(&nullDesc); err = AECreateDesc( typeNull, NULL, NULL, &nullDesc ); // set up the driver desc AEInitializeDesc(&keyData); tmpIndex = 1; err = AECreateDesc( typeUInt32, &tmpIndex, // This is the Tablet Driver Index. Always 1 sizeof(tmpIndex), &keyData ); err = CreateObjSpecifier(cWTDDriver, &nullDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType != cWTDDriver) { // set up the tablet desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->tabletIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDTablet, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType != cWTDTablet) { // set up the cutom app desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->applicationIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDCustomizedApp, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType != cWTDCustomizedApp) { if (pTabletObject->objectType == cWTDButton) { // set up the transducer desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->transducerIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDTransducer, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); } if (pTabletObject->objectType == cWTDTransducer) { // set up the transducer desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->transducerIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDTransducer, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); } else // cWTDButton || cWTDMenuItem || cWTDButton { // set up the transducer desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->auxIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(pTabletObject->objectType, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); } } } } AEInitializeDesc(&keyData); err = AECreateDesc( typeType, &attribute, // This is the Attribute we want to set sizeof(DescType), &keyData ); err = CreateObjSpecifier(cProperty, &lastDesc, formPropertyID, &keyData, TRUE, &tObjSpecifier); // Add the data to set to the AE here. err = AEPutParamPtr ( &aeSend, keyAEData, dataType, inDataPtr, inDataSize); err = AEPutParamDesc( &aeSend, keyDirectObject, &tObjSpecifier); // The Object chain // Finally send the event err = AESend(&aeSend, // The complete AE we created above NULL, // Don't need a reply kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend); return err;
// GetData_ofSize_ofType_ofContext_ForAttribute // // This function will get an attribute of a context your app created. See // Context Attributes near the bottom of the TabletAEDictionary.h header file. // // parameters: const void *inDataPtr - Location to store the attribute data. // Size inDataSize - Size of the data buffer pointed to above. // DescType dataType - Type of data bufferpointed to above. // UInt32 contextID - The context to get from. // DescType attribute - The attribute you want to get. // // returns: noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr GetData_ofSize_ofType_ofContext_ForAttribute(void *inDataPtr, Size inDataSize, DescType dataType, UInt32 contextID, DescType attribute) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; AEDesc lastDesc; AppleEvent aeSend; AppleEvent aeReply; DescType outType; Size outSize; OSErr err; // assert(inDataPtr); if(!inDataPtr) { return -1; } err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAEGetData, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to get // We have to set up a chain here. // Attribute -> Context -> null // The thing is, Apple Events are built backwards. So... //Create NULL AEDesc, this will signify the end of the AEDesc Chain AEInitializeDesc(&nullDesc); err = AECreateDesc( typeNull, NULL, NULL, &nullDesc ); AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &contextID, // This is the context ID that we want to modify sizeof(contextID), &keyData ); err = CreateObjSpecifier(cContext, // We want to modifiy a context attribute &nullDesc, // This is the last item in the chain formUniqueID, // use id to determine which context to modify &keyData, // This is the Context ID descriptor created above TRUE, // delete the nullDesc, and KeyData descriptor for us &tObjSpecifier); // The created descriptor which says that we want to modify Context X AEDuplicateDesc(&tObjSpecifier, &lastDesc); AEDisposeDesc(&tObjSpecifier); AEInitializeDesc(&keyData); err = AECreateDesc( typeType, &attribute, // This is the Attribute we want to set sizeof(DescType), &keyData ); err = CreateObjSpecifier(cProperty, // We want to destroy a context &lastDesc, // This is the last item in the chain (the Context) formPropertyID, // use id to determine which context to destroy &keyData, // This is the Context ID descriptor created above TRUE, // delete the nullDesc, and KeyData descriptor for us &tObjSpecifier); // The created descriptor which says that we want to delete Context X // Add the data to set to the AE here. err = AEPutParamPtr ( &aeSend, keyAERequestedType, typeType, &dataType, sizeof(DescType)); // The Object chain (Attribute -> Context -> null) err = AEPutParamDesc( &aeSend, keyDirectObject, &tObjSpecifier); // Finally send the event err = AESend(&aeSend, // The complete AE we created above &aeReply, kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); if(!err) { err = AEGetParamPtr(&aeReply, keyDirectObject, dataType, &outType, inDataPtr, // Put the answer into this variable inDataSize, &outSize); } AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend); AEDisposeDesc(&aeReply);
static VALUE rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE params, VALUE need_retval) { OSErr error; AppleEvent ae; AppleEvent reply; VALUE rb_timeout; SInt32 timeout; VALUE rb_reply; unsigned has_direct_param; error = AECreateAppleEvent (RVAL2FOURCHAR (event_class), RVAL2FOURCHAR (event_id), rbosa_element_aedesc (self), kAutoGenerateReturnID, kAnyTransactionID, &ae); if (error != noErr) rb_raise (rb_eArgError, "Cannot create Apple Event '%s%s' : %s (%d)", RVAL2CSTR (event_class), RVAL2CSTR (event_id), error_code_to_string (error), error); has_direct_param = 0; if (!NIL_P (params)) { unsigned i; for (i = 0; i < RARRAY (params)->len; i++) { VALUE ary; VALUE type; VALUE element; FourCharCode code; ary = RARRAY (params)->ptr[i]; if (NIL_P (ary) || RARRAY (ary)->len != 2) continue; type = RARRAY (ary)->ptr[0]; element = RARRAY (ary)->ptr[1]; code = RVAL2FOURCHAR (type); if (code == '----') has_direct_param = 1; error = AEPutParamDesc (&ae, RVAL2FOURCHAR (type), rbosa_element_aedesc (element)); if (error != noErr) { AEDisposeDesc (&ae); rb_raise (rb_eArgError, "Cannot add Apple Event parameter '%s' : %s (%d)", RVAL2CSTR (type), error_code_to_string (error), error); } } } rb_timeout = rb_iv_get (mOSA, "@timeout"); timeout = NIL_P (rb_timeout) ? kAEDefaultTimeout : NUM2INT (rb_timeout); if (has_direct_param == 0) AEPutAttributePtr (&ae, 'subj', typeNull, NULL, 0); error = AESend (&ae, &reply, (RVAL2CBOOL(need_retval) ? kAEWaitReply : kAENoReply) | kAECanInteract | kAECanSwitchLayer, kAENormalPriority, timeout, NULL, NULL); AEDisposeDesc (&ae); if (error != noErr) rb_raise (rb_eRuntimeError, "Cannot send Apple Event '%s%s' : %s (%d)", RVAL2CSTR (event_class), RVAL2CSTR (event_id), error_code_to_string (error), error); __rbosa_raise_potential_app_error (&reply); if (RTEST (need_retval)) { AEDesc replyObject; AEGetParamDesc (&reply, keyDirectObject, typeWildCard, &replyObject); rb_reply = rbosa_element_make (cOSAElement, &replyObject, self); } else { rb_reply = Qnil; } AEDisposeDesc (&reply); return rb_reply; }
// CreateWacomContextForTablet // // This function will instruct the Tablet Driver to create a context for your // application that you can then modify. For example, you can modify your // context to change the tablet mapping or to diconnect the tablet from the // cursor. // // parameters: UInt32 tabletIdx - Tablet Number you want to a context for // UInt32 *contextID - On return, the ID used to modify / delete // your context. // // returns: a contextID and noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr CreateWacomContextForTablet(UInt32 tabletIdx, UInt32 *contextID) { AEDesc driverTarget,nullDesc,keyData,tObjSpecifier; DescType objectToMake = cContext; UInt32 outContextID; DescType outType; Size outSize; AppleEvent aeSend; AppleEvent aeReply; OSErr err; err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAECreateElement, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to create err = AEPutParamPtr( &aeSend, keyAEObjectClass, typeType, &objectToMake, sizeof(DescType)); // Now tell the AE where to create a context //Create NULL AEDesc, this will signify the end of the AEDesc Chain AEInitializeDesc(&nullDesc); err = AECreateDesc( typeNull, NULL, NULL, &nullDesc ); AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &tabletIdx, // This is the tablet number we want the context for sizeof(tabletIdx), &keyData ); err = CreateObjSpecifier(cWTDTablet, // We want info from a tablet &nullDesc, // This is the last item in the chain formAbsolutePosition, // use indexing to determine which tablet to get data from &keyData, // This is the Tablet Number descriptor created above TRUE, // delete the nullDesc, and KeyData descriptor for us &tObjSpecifier); // The created descriptor which says that we want data from tablet number X err = AEPutParamDesc( &aeSend, keyAEInsertHere, &tObjSpecifier); // Finally send the event err = AESend(&aeSend, // The complete AE we created above &aeReply, // The reply event that contains the Context ID. kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend); // Get the Context ID out of the reply err = AEGetParamPtr(&aeReply, keyDirectObject, typeUInt32, &outType, &outContextID, // Put the answer into this variable sizeof(long), &outSize); if(!err) { if(contextID) { *contextID = outContextID; } } AEDisposeDesc(&aeReply);
// CountTabletObjects // // This function will return the number of particular items the Tablet Driver // knows about. For examle, the number of tablets, the number of transducers // for a customized application for a particular tablet... // // parameters: TAEObject *pTabletObject - Pointer to a TAEObject that // describes exactly which tablet object // you want to count. // UInt32 *outCount - The number of pTabletObjects the driver knows // about. // // returns: noErr on success, else an AE error code ////////////////////////////////////////////////////////////////////////////// OSErr CountTabletObjects(TAEObject *pTabletObject, UInt32 *outCount) { AEDesc driverTarget,keyData,tObjSpecifier; AEDesc lastDesc; AppleEvent aeSend; AppleEvent aeReply; DescType outType; Size outSize; UInt32 tmpIndex = 0; UInt32 tmpCount = 0; OSErr err; // assert(outCount); if(!outCount) { return -1; } err = GetTabletDriverTarget(&driverTarget); if(err) { return err; } err = AECreateAppleEvent(kAECoreSuite, kAECountElements, &driverTarget, kAutoGenerateReturnID, kAnyTransactionID, &aeSend); // Now tell the AE what to Count // We have to set up a chain here. // [Button ->] [Transducer ->] [Application ->] Tablet -> null // The thing is, Apple Events are built backwards. So... //Create NULL AEDesc, this will signify the end of the AEDesc Chain AEInitializeDesc(&lastDesc); err = AECreateDesc( typeNull, NULL, NULL, &lastDesc ); if (pTabletObject->objectType != cWTDDriver) { // set up the driver desc AEInitializeDesc(&keyData); tmpIndex = 1; err = AECreateDesc( typeUInt32, &tmpIndex, // This is the Tablet Driver Index. Always 1 sizeof(tmpIndex), &keyData ); err = CreateObjSpecifier(cWTDDriver, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType != cWTDTablet) { // set up the tablet desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->tabletIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDTablet, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType != cWTDCustomizedApp) { // set up the cutom app desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->applicationIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDCustomizedApp, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); if (pTabletObject->objectType == cWTDButton) { // set up the transducer desc AEInitializeDesc(&keyData); err = AECreateDesc( typeUInt32, &pTabletObject->transducerIndex, sizeof(UInt32), &keyData ); err = CreateObjSpecifier(cWTDTransducer, &lastDesc, formAbsolutePosition, &keyData, TRUE, &tObjSpecifier); AEDuplicateDesc(&tObjSpecifier,&lastDesc); AEDisposeDesc(&tObjSpecifier); } } } } // Now we actually tell it to count the number of the tablet objects err = AEPutParamPtr( &aeSend, keyAEObjectClass, typeType, &pTabletObject->objectType, // This is the class of objects to count sizeof(DescType) ); err = AEPutParamDesc( &aeSend, keyDirectObject, &lastDesc); // The Object chain // Finally send the event err = AESend(&aeSend, // The complete AE we created above &aeReply, kAEWaitReply, kAEHighPriority, kDefaultTimeOut, NULL, NULL); if(!err) { // Get the answer from the Reply err = AEGetParamPtr(&aeReply, keyDirectObject, typeUInt32, &outType, &tmpCount, // Put the answer into this variable sizeof(long), &outSize); if(noErr != err) { tmpCount = 0; } else { *outCount = tmpCount; } } AEDisposeDesc(&tObjSpecifier); AEDisposeDesc(&aeSend); AEDisposeDesc(&aeReply); return err;
OSErr FinderLaunch(const char *target) { OSErr err; AppleEvent theAEvent, theReply; AEAddressDesc fndrAddress; AEDescList targetListDesc; OSType fndrCreator; AliasHandle targetAlias; FSSpec fileinfo; FSRef privateInfo; /* * FSPathMakeRef needs (UInt8 *) as its first argument, but my current * understanding is that this is "just" a string but in an exlicitly * 8-bit code. Thus "char *" ought to suffice UNLESS you are compiling in a * world where char is a 16-bit item or some other wide-char messing about is * happening. The C compiler with 10.3 adjusted things without an explicit * cast hear and gave a warning. WIth 10.4 it gives an error. * ACN, August 2005 */ err = FSPathMakeRef((const UInt8 *)target, &privateInfo, NULL); #ifdef DEBUG printf("FSPathMakeRef()-> %d\n", err); #endif err = FSGetCatalogInfo(&privateInfo, kFSCatInfoNone, NULL, NULL, &fileinfo, NULL); #ifdef DEBUG printf("FSGetCatalogInfo()-> %d\n",err); #endif /* set up locals */ AECreateDesc(typeNull, NULL, 0, &theAEvent); AECreateDesc(typeNull, NULL, 0, &fndrAddress); AECreateDesc(typeNull, NULL, 0, &theReply); AECreateDesc(typeNull, NULL, 0, &targetListDesc); targetAlias = NULL; fndrCreator = 'MACS'; /* create an open documents event targeting the finder */ err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator, sizeof(fndrCreator), &fndrAddress); #ifdef DEBUG printf("AECreateDesc()-> %d\n",err); #endif if (err == noErr) { err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &fndrAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAEvent); #ifdef DEBUG printf("AECreateAppleEvent()-> %d\n",err); #endif } if (err == noErr) { err = AECreateList(NULL, 0, false, &targetListDesc); #ifdef DEBUG printf("AECreateList()-> %d\n", err); #endif } if (err == noErr) { err = NewAlias(NULL, &fileinfo, &targetAlias); #ifdef DEBUG printf("NewAlias()-> %d\n",err); #endif if (err == noErr) { HLock((Handle) targetAlias); err = AEPutPtr(&targetListDesc, 1, typeAlias, *targetAlias, GetHandleSize((Handle) targetAlias)); #ifdef DEBUG printf("AEPutPtr()-> %d\n",err); #endif HUnlock((Handle) targetAlias); } } /* add the file list to the apple event */ if( err == noErr ) { err = AEPutParamDesc(&theAEvent, keyDirectObject, &targetListDesc); #ifdef DEBUG printf("AEPutParamDesc()-> %d\n",err); #endif } if (err == noErr) { /* send the event to the Finder */ err = AESend(&theAEvent, &theReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); #ifdef DEBUG printf("AESend()-> %d\n",err); #endif } /* clean up and leave */ if (targetAlias != NULL) DisposeHandle((Handle) targetAlias); AEDisposeDesc(&targetListDesc); AEDisposeDesc(&theAEvent); AEDisposeDesc(&fndrAddress); AEDisposeDesc(&theReply); return err; }
static OSStatus SendEventToSystemEventsWithParameters( AEEventClass theClass, AEEventID theEvent, AppleEvent * reply, ... ) // Creates an Apple event and sends it to the System Events // process. theClass and theEvent are the event class and ID, // respectively. If reply is not NULL, the caller gets a copy // of the reply. Following reply is a variable number of Apple event // parameters. Each AE parameter is made up of two C parameters, // the first being the AEKeyword, the second being a pointer to // the AEDesc for that parameter. This list is terminated by an // AEKeyword of value 0. // // You typically call this as: // // err = SendEventToSystemEventsWithParameters( // kClass, // kEvent, // NULL, // param1_keyword, param1_desc_ptr, // param2_keyword, param2_desc_ptr, // 0 // ); // // On entry, reply must be NULL or *reply must be the null AEDesc. // On success, if reply is not NULL, *reply will be the AE reply // (that is, not a null desc). // On error, if reply is not NULL, *reply will be the null AEDesc. { OSStatus err; ProcessSerialNumber psn; AppleEvent target; AppleEvent event; AppleEvent localReply; AEDescList results; assert( (reply == NULL) || (reply->descriptorType == typeNull) ); target = kAENull; event = kAENull; localReply = kAENull; results = kAENull; // Create Apple event. err = FindSystemEvents(&psn); if (err == noErr) { err = AECreateDesc(typeProcessSerialNumber, &psn, sizeof(psn), &target); } if (err == noErr) { err = AECreateAppleEvent( theClass, theEvent, &target, kAutoGenerateReturnID, kAnyTransactionID, &event ); } // Handle varargs parameters. if (err == noErr) { va_list ap; AEKeyword thisKeyword; const AEDesc * thisDesc; va_start(ap, reply); do { thisKeyword = va_arg(ap, AEKeyword); if (thisKeyword != 0) { thisDesc = va_arg(ap, const AEDesc *); assert(thisDesc != NULL); err = AEPutParamDesc(&event, thisKeyword, thisDesc); } } while ( (err == noErr) && (thisKeyword != 0) ); va_end(ap); }
OSErr FinderLaunch(long nTargets, FSSpec *targetList) { OSErr err; AppleEvent theAEvent, theReply; AEAddressDesc fndrAddress; AEDescList targetListDesc; OSType fndrCreator; Boolean wasChanged; AliasHandle targetAlias; long index; /* verify parameters */ if ((nTargets == 0) || (targetList == NULL)) return paramErr; /* set up locals */ AECreateDesc(typeNull, NULL, 0, &theAEvent); AECreateDesc(typeNull, NULL, 0, &fndrAddress); AECreateDesc(typeNull, NULL, 0, &theReply); AECreateDesc(typeNull, NULL, 0, &targetListDesc); targetAlias = NULL; fndrCreator = 'MACS'; /* create an open documents event targeting the finder */ err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator, sizeof(fndrCreator), &fndrAddress); if (err != noErr) goto bail; err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &fndrAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAEvent); if (err != noErr) goto bail; /* create the list of files to open */ err = AECreateList(NULL, 0, false, &targetListDesc); if (err != noErr) goto bail; for ( index=0; index < nTargets; index++) { if (targetAlias == NULL) err = NewAlias(NULL, (targetList + index), &targetAlias); else err = UpdateAlias(NULL, (targetList + index), targetAlias, &wasChanged); if (err != noErr) goto bail; HLock((Handle) targetAlias); err = AEPutPtr(&targetListDesc, (index + 1), typeAlias, *targetAlias, GetHandleSize((Handle) targetAlias)); HUnlock((Handle) targetAlias); if (err != noErr) goto bail; } /* add the file list to the apple event */ err = AEPutParamDesc(&theAEvent, keyDirectObject, &targetListDesc); if (err != noErr) goto bail; /* send the event to the Finder */ err = AESend(&theAEvent, &theReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); /* clean up and leave */ bail: if (targetAlias != NULL) DisposeHandle((Handle) targetAlias); AEDisposeDesc(&targetListDesc); AEDisposeDesc(&theAEvent); AEDisposeDesc(&fndrAddress); AEDisposeDesc(&theReply); return err; }