static PyObject *AEDesc_AEPutPtr(AEDescObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; long index; DescType typeCode; char *dataPtr__in__; long dataPtr__len__; int dataPtr__in_len__; #ifndef AEPutPtr PyMac_PRECHECK(AEPutPtr); #endif if (!PyArg_ParseTuple(_args, "lO&s#", &index, PyMac_GetOSType, &typeCode, &dataPtr__in__, &dataPtr__in_len__)) return NULL; dataPtr__len__ = dataPtr__in_len__; _err = AEPutPtr(&_self->ob_itself, index, typeCode, dataPtr__in__, dataPtr__len__); if (_err != noErr) return PyMac_Error(_err); Py_INCREF(Py_None); _res = Py_None; return _res; }
/******************************************************************************** Make position list (a list containing two longs representin the x and y values for the position of a Finder item). pPosition input: A point specifying the position. pPositionAEList input: Pointer to an AEList (contents will be lost, but not disposed). output: A new AEList containing the x & y values for the position. Result Codes ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone */ pascal OSErr MoreAEOCreatePositionList( const Point pPosition, AEDescList * pPositionAEList ) { OSErr anErr = noErr; anErr = AECreateList( NULL, 0, false, pPositionAEList ); if ( noErr == anErr ) { long h = pPosition.h; long v = pPosition.v; anErr = AEPutPtr( pPositionAEList, 0, typeInteger, &h, sizeof(h) ); if ( noErr == anErr ) anErr = AEPutPtr( pPositionAEList, 0, typeInteger, &v, sizeof(v) ); } return anErr; }//end MoreAEOCreatePositionList
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 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; }
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; }