Beispiel #1
0
/*----------------------------------------------------------------------------
	GetDataFromList 

	
----------------------------------------------------------------------------*/
void AEGenericClass::GetDataFromList(const AEDesc *srcList, AEDesc *desiredTypes, AEDesc *dstList)
{
	OSErr		err;
	long			itemNum;
	long			numItems;
	DescType		keyword;
	StAEDesc		srcItem;
	StAEDesc		dstItem;
		
	err = AECountItems((AEDescList*)srcList, &numItems);
	ThrowIfOSErr(err);
		
	for (itemNum = 1; itemNum <= numItems; itemNum++)
	{
		err = AEGetNthDesc(srcList, itemNum, typeWildCard, &keyword, &srcItem);
		ThrowIfOSErr(err);
		
		if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
		{
			GetDataFromObject(&srcItem, desiredTypes, &dstItem);  // Get data from single item
		}
		else
		{
			ThrowIfOSErr(AECreateList(nil, 0, false, &dstItem));
			GetDataFromList(&srcItem, desiredTypes, &dstItem);
		}
		err = AEPutDesc(dstList, itemNum, &dstItem);
		ThrowIfOSErr(err);
	}
}
Beispiel #2
0
static VALUE
rbosa_elementlist_new (int argc, VALUE *argv, VALUE self)
{
    OSErr           error;
    AEDescList      list;
    VALUE           ary;
    int             i;

    rb_scan_args (argc, argv, "01", &ary);

    if (!NIL_P (ary))
        Check_Type (ary, T_ARRAY);

    error = AECreateList (NULL, 0, false, &list);
    if (error != noErr) 
        rb_raise (rb_eRuntimeError, "Cannot create Apple Event descriptor list : %s (%d)", 
                  error_code_to_string (error), error);

    if (!NIL_P (ary)) {
        for (i = 0; i < RARRAY (ary)->len; i++)
            __rbosa_elementlist_add (&list, RARRAY (ary)->ptr[i], i + 1); 
    }
    
    return rbosa_element_make (self, &list, Qnil);
}
Beispiel #3
0
static PyObject *AE_AECreateList(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	char *factoringPtr__in__;
	long factoringPtr__len__;
	int factoringPtr__in_len__;
	Boolean isRecord;
	AEDescList resultList;
#ifndef AECreateList
	PyMac_PRECHECK(AECreateList);
#endif
	if (!PyArg_ParseTuple(_args, "s#b",
	                      &factoringPtr__in__, &factoringPtr__in_len__,
	                      &isRecord))
		return NULL;
	factoringPtr__len__ = factoringPtr__in_len__;
	_err = AECreateList(factoringPtr__in__, factoringPtr__len__,
	                    isRecord,
	                    &resultList);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O&",
	                     AEDesc_New, &resultList);
	return _res;
}
Beispiel #4
0
OSErr CreateAEListFromIDs(unsigned int* id_nums, long count, DescType object_type, AEDescList* list)
{
	int i;
	OSStatus err;
	err = AECreateList(NULL, 0, false, list);
	for (i = 0; i < count && err == noErr; i++)
	{
		err = AddIDToAEList(id_nums[i], i+1, object_type, list);
	}
	return err;
}
Beispiel #5
0
void AEGenericClass::GetDataFromListOrObject(const AEDesc *tokenOrTokenList, AEDesc *desiredTypes, AEDesc *data)
{
	if (AEListUtils::TokenContainsTokenList(tokenOrTokenList) == false)
	{
		GetDataFromObject(tokenOrTokenList, desiredTypes, data);
	}
	else
	{
		ThrowIfOSErr(AECreateList(nil, 0, false, data));
		GetDataFromList(tokenOrTokenList, desiredTypes, data);
	}
}
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( &params, NULL );
    AEDisposeDesc( &argAEList );
    AEDisposeDesc( &target );
}
Beispiel #7
0
static PyObject *AE_AECreateRecord(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSErr _err;
	AEDescList resultList;

	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = AECreateList(NULL, 0,
	                    1,
	                    &resultList);
	if (_err != noErr) return AE_MacOSError(_err);
	_res = Py_BuildValue("O&",
	                     AE_AEDesc_New, &resultList);
	return _res;
}
Beispiel #8
0
/********************************************************************************
	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
Beispiel #9
0
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);
}
Beispiel #10
0
/*----------------------------------------------------------------------------
	GetPropertyFromListOrObject 

----------------------------------------------------------------------------*/
void AEGenericClass::GetPropertyFromListOrObject(		DescType			desiredClass,
												const AEDesc*		containerToken,
												DescType			containerClass,
												DescType			keyForm,
												const AEDesc*		keyData,
												AEDesc*			resultToken)
{
	if (AEListUtils::TokenContainsTokenList((AEDescList*)containerToken) == false)
	{
		GetPropertyFromObject(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
	}
	else
	{
		OSErr	err = AECreateList(nil, 0, false, resultToken);
		ThrowIfOSErr(err);
		
		GetPropertyFromList(desiredClass, containerToken, containerClass, keyForm, keyData, resultToken);
	}
}
Beispiel #11
0
// A proper object descriptor has 4 parts:
// - What class it is
// - How it is being identified (in our case an ID number, specified by formUniqueID)
// - The identification itself
// - The parent of the object
OSErr CreateAEDescFromID(unsigned int id_num, DescType object_type, AEDesc* item_desc)
{
	AEDesc item_record;
	unsigned int form = formUniqueID;
	OSStatus err;
	err = AECreateList(NULL, 0, true, &item_record);
	if (err == noErr) {
		AERecord * record = &item_record;
		err = AEPutKeyPtr(record, keyAEDesiredClass, cType, &object_type, sizeof(object_type));
		err |= AEPutKeyPtr(record, keyAEContainer, typeNull, NULL, 0);	// No parent
		err |= AEPutKeyPtr(record, keyAEKeyForm, cEnumeration, &form, sizeof(form));
		err |= AEPutKeyPtr(record, keyAEKeyData, typeUInt32, &id_num, sizeof(id_num));
		if (err == noErr)
		{
			err = AECoerceDesc(record, typeObjectSpecifier, item_desc);
		}
		AEDisposeDesc(&item_record);
	}
	return err;
}
Beispiel #12
0
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;
}
Beispiel #13
0
/*----------------------------------------------------------------------------
	GetPropertyFromList 

----------------------------------------------------------------------------*/
void AEGenericClass::GetPropertyFromList(				DescType			desiredClass,
												const AEDesc*		containerToken,
												DescType			containerClass,
												DescType			keyForm,
												const AEDesc*		keyData,
												AEDesc*			resultToken)
{
	OSErr		err		= noErr;
	long			itemNum;
	long			numItems;
	DescType		keyword;
	
	err = AECountItems((AEDescList*)containerToken, &numItems);
	ThrowIfOSErr(err);
		
	for (itemNum = 1; itemNum <= numItems; itemNum++)
	{
		StAEDesc		srcItem;
		StAEDesc		dstItem;
		
		err = AEGetNthDesc(containerToken, itemNum, typeWildCard, &keyword, &srcItem);
		ThrowIfOSErr(err);
		
		if (AEListUtils::TokenContainsTokenList(&srcItem) == false)
		{
			GetPropertyFromObject(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
		}
		else
		{
			err = AECreateList(nil, 0, false, &dstItem);
			ThrowIfOSErr(err);
			
			GetPropertyFromList(desiredClass, &srcItem, containerClass, keyForm, keyData, &dstItem);
		}

		err = AEPutDesc(resultToken, itemNum, &dstItem);
		ThrowIfOSErr(err);
	}
	
}
Beispiel #14
0
// "get first window"
// "get last window"
// "get middle window"
// "get some window"
// "get windows"
OSErr CreateDescForOrdinalWindow(DescType ordinal, Boolean toplevel, BrowserDesktopWindow* container, AEDesc* item_desc)
{
	DescType data_desc = toplevel ? (DescType)cWindow : (DescType)cDocument;
	OSStatus err;
	DesktopWindow* win;
	if (ordinal == kAEAll)
	{
		// Special case. GetOrdinalWindow can only return one window.
		int count = 1;
		err = AECreateList(NULL, 0, false, item_desc);
		while (err == noErr && (win = GetNumberedWindow(count, toplevel, container)))
		{
			err = AddIDToAEList(GetExportIDForDesktopWindow(win, toplevel), count, data_desc, item_desc);
			count++;
		}
		return err;
	}
	win = GetOrdinalWindow(ordinal, toplevel, container);
	if (win)
		return CreateAEDescFromID(GetExportIDForDesktopWindow(win, toplevel), data_desc, item_desc);
	return paramErr;
}
Beispiel #15
0
static VALUE
rbosa_elementrecord_new (int argc, VALUE *argv, VALUE self)
{
    OSErr           error;
    AEDescList      list;
    VALUE           hash;

    rb_scan_args (argc, argv, "01", &hash);

    if (!NIL_P (hash))
        Check_Type (hash, T_HASH);

    error = AECreateList (NULL, 0, true, &list);
    if (error != noErr) 
        rb_raise (rb_eRuntimeError, "Cannot create Apple Event descriptor list : %s (%d)", 
                  error_code_to_string (error), error);

    if (!NIL_P (hash)) 
        rb_hash_foreach (hash, __rbosa_elementrecord_set, (VALUE)&list);
    
    return rbosa_element_make (self, &list, Qnil);
}
Beispiel #16
0
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;
}
Beispiel #17
0
// -----------------------------------------------------------------------------
//	AddCommandToAEDescList
// -----------------------------------------------------------------------------
static OSStatus AddCommandToAEDescList(
	ConstStr255Param		inCommandString,
	TextEncoding			inEncoding,
	DescType				inDescType,
	SInt32					inCommandID,
	MenuItemAttributes		inAttributes,
	UInt32					inModifiers,
	AEDescList*				ioCommandList)
{
	OSStatus theError = noErr;
	
	AERecord theCommandRecord = { typeNull, NULL };
	
	printf( "AddCommandToAEDescList: Trying to add an item.\n" );

	// create an apple event record for our command
	theError = AECreateList( NULL, kAEDescListFactorNone, true, &theCommandRecord );
	require_noerr( theError, AddCommandToAEDescList_fail );
	
	// stick the command text into the AERecord
	if ( inCommandString != NULL )
	{
		if ( inDescType == typeChar )
		{
			theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeChar,
				&inCommandString[1], StrLength( inCommandString ) );
			require_noerr( theError, AddCommandToAEDescList_fail );
		}
		else if ( inDescType == typeStyledText )
		{
			AERecord	textRecord;
			WritingCode	writingCode;
			AEDesc		textDesc;
			
			theError = AECreateList( NULL, kAEDescListFactorNone, true, &textRecord );
			require_noerr( theError, AddCommandToAEDescList_fail );
			
			theError = AEPutKeyPtr( &textRecord, keyAEText, typeChar,
				&inCommandString[1], StrLength( inCommandString ) );
			require_noerr( theError, AddCommandToAEDescList_fail );
			
			RevertTextEncodingToScriptInfo( inEncoding, &writingCode.theScriptCode,
				&writingCode.theLangCode, NULL );
			theError = AEPutKeyPtr( &textRecord, keyAEScriptTag, typeIntlWritingCode,
				&writingCode, sizeof( writingCode ) );
			require_noerr( theError, AddCommandToAEDescList_fail );

			theError = AECoerceDesc( &textRecord, typeStyledText, &textDesc );
			require_noerr( theError, AddCommandToAEDescList_fail );
			
			theError = AEPutKeyDesc( &theCommandRecord, keyAEName, &textDesc );
			require_noerr( theError, AddCommandToAEDescList_fail );
			
			AEDisposeDesc( &textRecord );
		}
		else if ( inDescType == typeIntlText )
		{
			IntlText*	intlText;
			ByteCount	size = sizeof( IntlText ) + StrLength( inCommandString ) - 1;
			
			// create an IntlText structure with the text and script
			intlText = (IntlText*) malloc( size );
			RevertTextEncodingToScriptInfo( inEncoding, &intlText->theScriptCode,
				&intlText->theLangCode, NULL );
			BlockMoveData( &inCommandString[1], &intlText->theText, StrLength( inCommandString ) );
			
			theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeIntlText, intlText, size );
			free( (char*) intlText );
			require_noerr( theError, AddCommandToAEDescList_fail );
		}
		else if ( inDescType == typeUnicodeText )
		{
			CFStringRef str = CFStringCreateWithPascalString( NULL, inCommandString, inEncoding );
			if ( str != NULL )
			{
				Boolean doFree = false;
				CFIndex sizeInChars = CFStringGetLength( str );
				CFIndex sizeInBytes = sizeInChars * sizeof( UniChar );
				const UniChar* unicode = CFStringGetCharactersPtr( str );
				if ( unicode == NULL )
				{
					doFree = true;
					unicode = (UniChar*) malloc( sizeInBytes );
					CFStringGetCharacters( str, CFRangeMake( 0, sizeInChars ), (UniChar*) unicode );
				}
				
				theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeUnicodeText, unicode, sizeInBytes );
					
				CFRelease( str );
				if ( doFree )
					free( (char*) unicode );
				
				require_noerr( theError, AddCommandToAEDescList_fail );
			}
		}
		else if ( inDescType == typeCFStringRef )
		{
			CFStringRef str = CFStringCreateWithPascalString( NULL, inCommandString, inEncoding );
			if ( str != NULL )
			{
				theError = AEPutKeyPtr( &theCommandRecord, keyAEName, typeCFStringRef, &str, sizeof( str ) );
				require_noerr( theError, AddCommandToAEDescList_fail );
				
				// do not release the string; the Contextual Menu Manager will release it for us
			}
		}
	}
		
	// stick the command ID into the AERecord
	if ( inCommandID != 0 )
	{
		theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuCommandID,
				typeLongInteger, &inCommandID, sizeof( inCommandID ) );
		require_noerr( theError, AddCommandToAEDescList_fail );
	}
	
	// stick the attributes into the AERecord
	if ( inAttributes != 0 )
	{
		theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuAttributes,
				typeLongInteger, &inAttributes, sizeof( inAttributes ) );
		require_noerr( theError, AddCommandToAEDescList_fail );
	}
	
	// stick the modifiers into the AERecord
	if ( inModifiers != 0 )
	{
		theError = AEPutKeyPtr( &theCommandRecord, keyContextualMenuModifiers,
				typeLongInteger, &inModifiers, sizeof( inModifiers ) );
		require_noerr( theError, AddCommandToAEDescList_fail );
	}
	
	// stick this record into the list of commands that we are
	// passing back to the CMM
	theError = AEPutDesc(
			ioCommandList, 			// the list we're putting our command into
			0, 						// stick this command onto the end of our list
			&theCommandRecord );	// the command I'm putting into the list
	
AddCommandToAEDescList_fail:
	// clean up after ourself; dispose of the AERecord
	AEDisposeDesc( &theCommandRecord );

    return theError;
    
} // AddCommandToAEDescList
Beispiel #18
0
// -----------------------------------------------------------------------------
//	CreateSampleSubmenu
// -----------------------------------------------------------------------------
static OSStatus CreateSampleSubmenu(
	AEDescList*		ioCommandList)
{
	OSStatus	theError = noErr;
	
	AEDescList	theSubmenuCommands = { typeNull, NULL };
	AERecord	theSupercommand = { typeNull, NULL };
	Str255		theSupercommandText = "\pSubmenu Here";
	
	// the first thing we should do is create an AEDescList of
	// subcommands

	// set up the AEDescList
	theError = AECreateList( NULL, 0, false, &theSubmenuCommands );
	require_noerr( theError, CreateSampleSubmenu_Complete_fail );

	// stick some commands in this subcommand list
	theError = AddCommandToAEDescList( "\pSubcommand 1", kTextEncodingMacRoman, typeChar,
			1001, 0, 0, &theSubmenuCommands );
	require_noerr( theError, CreateSampleSubmenu_CreateDesc_fail );
	
	// another
	theError = AddCommandToAEDescList( "\pAnother Subcommand", kTextEncodingMacRoman, typeChar,
			1002, 0, 0, &theSubmenuCommands );
	require_noerr( theError, CreateSampleSubmenu_fail );
	
	// yet another
	theError = AddCommandToAEDescList( "\pLast One", kTextEncodingMacRoman, typeChar, 
			1003, 0, 0, &theSubmenuCommands);
	require_noerr( theError, CreateSampleSubmenu_fail );
		
	// now, we need to create the supercommand which will "own" the
	// subcommands.  The supercommand lives in the root command list.
	// this looks very much like the AddCommandToAEDescList function,
	// except that instead of putting a command ID in the record,
	// we put in the subcommand list.

	// create an apple event record for our supercommand
	theError = AECreateList( NULL, 0, true, &theSupercommand );
	require_noerr( theError, CreateSampleSubmenu_fail );
	
	// stick the command text into the aerecord
	theError = AEPutKeyPtr(&theSupercommand, keyAEName, typeChar,
		&theSupercommandText[1], StrLength( theSupercommandText ) );
	require_noerr( theError, CreateSampleSubmenu_fail );
	
	// stick the subcommands into into the AERecord
	theError = AEPutKeyDesc(&theSupercommand, keyContextualMenuSubmenu,
		&theSubmenuCommands);
	require_noerr( theError, CreateSampleSubmenu_fail );
	
	// stick the supercommand into the list of commands that we are
	// passing back to the CMM
	theError = AEPutDesc(
		ioCommandList,		// the list we're putting our command into
		0,					// stick this command onto the end of our list
		&theSupercommand);	// the command I'm putting into the list
	
	// clean up after ourself
CreateSampleSubmenu_fail:
	AEDisposeDesc(&theSubmenuCommands);

CreateSampleSubmenu_CreateDesc_fail:
	AEDisposeDesc(&theSupercommand);

CreateSampleSubmenu_Complete_fail:
    return theError;
    
} // CreateSampleSubmenu
Beispiel #19
0
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;
}