Beispiel #1
0
pascal OSErr MoreFESetComment(const FSSpecPtr pFSSpecPtr, const Str255 pCommentStr, const AEIdleUPP pIdleProcUPP){
	AppleEvent tAppleEvent = {
		typeNull, nil
	};                                              // If you always init AEDescs, it's always safe to dispose of them.
	AEBuildError tAEBuildError;
	AEDesc tAEDesc = {
		typeNull, nil
	};
	OSErr anErr = noErr;

	anErr = MoreAEOCreateObjSpecifierFromFSSpec(pFSSpecPtr, &tAEDesc);
	if (noErr == anErr) {
		char *dataPtr = NewPtr(pCommentStr[ 0 ]);

		CopyPascalStringToC(pCommentStr, dataPtr);
		anErr = AEBuildAppleEvent(
		        kAECoreSuite, kAESetData,
		        typeApplSignature, &gFinderSignature, sizeof( OSType ),
		        kAutoGenerateReturnID, kAnyTransactionID,
		        &tAppleEvent, &tAEBuildError,
		        "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)},data:'TEXT'(@)",
		        &tAEDesc, dataPtr);

		DisposePtr(dataPtr);

		if (noErr == anErr) {
			// Send the event. In this case we don't care about the reply
			anErr = MoreAESendEventNoReturnValue(pIdleProcUPP, &tAppleEvent);
			(void) MoreAEDisposeDesc(&tAppleEvent); // always dispose of AEDescs when you are finished with them
		}
	}
	return anErr;
}
Beispiel #2
0
pascal OSErr MoreFEGetCommentCFString(const FSRefPtr pFSRefPtr, CFStringRef* pCommentStr,const AEIdleUPP pIdleProcUPP)
{
  AppleEvent tAppleEvent = {typeNull,NULL};  //  If you always init AEDescs, it's always safe to dispose of them.
  AEDesc tAEDesc = {typeNull,NULL};
  OSErr anErr = noErr;

  if (NULL == pIdleProcUPP)  // the idle proc is required
    return paramErr;


  anErr = MoreAEOCreateObjSpecifierFromFSRef(pFSRefPtr,&tAEDesc);

  if (noErr == anErr)
  {
    AEBuildError  tAEBuildError;

    anErr = AEBuildAppleEvent(
              kAECoreSuite,kAEGetData,
          typeApplSignature,&gFinderSignature,sizeof(OSType),
              kAutoGenerateReturnID,kAnyTransactionID,
              &tAppleEvent,&tAEBuildError,
              "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)}",&tAEDesc);

        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);

    if (noErr == anErr)
    {
#if 0  // Set this true to printf the Apple Event before you send it.
      Handle strHdl;
      anErr = AEPrintDescToHandle(&tAppleEvent,&strHdl);
      if (noErr == anErr)
      {
        char  nul  = '\0';
        PtrAndHand(&nul,strHdl,1);
        printf("\n-MoreFEGetCommentCFString: tAppleEvent=%s.",*strHdl); fflush(stdout);
        DisposeHandle(strHdl);
      }
#endif
      //  Send the event.
      anErr = MoreAESendEventReturnAEDesc(pIdleProcUPP,&tAppleEvent,typeUnicodeText,&tAEDesc);
      // always dispose of AEDescs when you are finished with them
      (void) MoreAEDisposeDesc(&tAppleEvent);
      if (noErr == anErr)
      {
        anErr = MoreAEGetCFStringFromDescriptor(&tAEDesc,pCommentStr);
        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);
      }
    }
  }
  return anErr;
}  // end MoreFEGetCommentCFString
Beispiel #3
0
pascal OSErr MoreFEGetComment(const FSRef *pFSRefPtr, const FSSpecPtr pFSSpecPtr,Str255 pCommentStr,const AEIdleUPP pIdleProcUPP)
{
  AppleEvent tAppleEvent = {typeNull,NULL};  //  If you always init AEDescs, it's always safe to dispose of them.
  AEDesc tAEDesc = {typeNull,NULL};
  OSErr anErr = noErr;

  if (NULL == pIdleProcUPP)  // the idle proc is required
  {
	fprintf(stderr, "No proc pointer\n");
    return paramErr;
  }
  anErr = MoreAEOCreateObjSpecifierFromFSRef(pFSRefPtr,&tAEDesc);
  if (anErr)
  {
	fprintf(stderr, "Error creating objspecifier from fsspec\n");
    return paramErr;
  }
  if (noErr == anErr)
  {
    AEBuildError  tAEBuildError;

    anErr = AEBuildAppleEvent(
              kAECoreSuite,kAEGetData,
          typeApplSignature,&gFinderSignature,sizeof(OSType),
              kAutoGenerateReturnID,kAnyTransactionID,
              &tAppleEvent,&tAEBuildError,
              "'----':obj {form:prop,want:type(prop),seld:type(comt),from:(@)}",&tAEDesc);

        // always dispose of AEDescs when you are finished with them
        (void) MoreAEDisposeDesc(&tAEDesc);

    if (noErr == anErr)
    {
      //  Send the event.
      anErr = MoreAESendEventReturnPString(pIdleProcUPP,&tAppleEvent,pCommentStr);
	  if (anErr)
	  {
		fprintf(stderr, "Error sending event to get pascal string\n");
	  }
      // always dispose of AEDescs when you are finished with them
      (void) MoreAEDisposeDesc(&tAppleEvent);
    }
	else
	{
		fprintf(stderr, "Error building Apple Event\n");
	}
  }
  return anErr;
}  // end MoreFEGetComment
Beispiel #4
0
bool document_is_open(CFStringRef docNameCF, ProcessSerialNumber *psn)
{
	char          docNameData[255];
	char          *docName = &docNameData[0];
	OSStatus      status;
	AppleEvent    ae, reply;
	AEBuildError  buildError;
	char          returnValue;
	char          *eventDescriptor;
	
	/* Apple Events only support MacRoman, I think */
	if (!CFStringGetCString(docNameCF, docName, 255, kCFStringEncodingMacRoman))
		give_up("Document name could not be encoded as MacRoman, or too long");
	
	if (docName[0] == '/')
		eventDescriptor =
			"'----':obj{form:enum('test'),want:type('docu'),seld:cmpd{relo:=,"
			"'obj1':obj{form:prop, want:type('prop'), seld:type('ppth'), from:exmn()},"
			"'obj2':TEXT(@)},from:null()}";
	else
		eventDescriptor =
			"'----':obj{form:enum('name'),want:type('docu'),seld:TEXT(@),from:null()}";

	status = AEBuildAppleEvent(kAECoreSuite, kAEDoObjectsExist,
		typeProcessSerialNumber, psn, sizeof(*psn),
		kAutoGenerateReturnID, kAnyTransactionID, &ae,
		&buildError, eventDescriptor, docName);
	if (status != noErr) {
		fprintf(stderr, "check_open: AEBuildAppleEvent failed: error %d at pos %lu\n",
			buildError.fError, buildError.fErrorPos);
		fprintf(stderr, "(See http://developer.apple.com/technotes/tn/tn2045.html#errstable)\n");
		exit(255);
	}
	
	status = AESendMessage(&ae, &reply,	kAEWaitReply, kAEDefaultTimeout);
	if (status != noErr)
		die("AESend failed");
	
	status = AEGetParamPtr (&reply, keyDirectObject, typeBoolean, 
		NULL, &returnValue, 1, NULL);
	if (status != noErr)
		/* Presumably this is because the reply is an error message */
		give_up("Application appears not to understand request");
	
	return (returnValue != 0);
	
    /* We don't need to bother disposing of things, because we're about to finish */
}
Beispiel #5
0
OSStatus
KeynoteChangeSlide(AEEventID eventID)
{
    OSStatus     err = noErr;
    AppleEvent   eventToSend = { typeNull, nil };
    AppleEvent   eventReply  = { typeNull, nil };
    AEBuildError eventBuildError;

    err = AEBuildAppleEvent(
              keynoteEventClass,     // Event class for the resulting event
              eventID,               // Event ID for the resulting event
              typeApplicationBundleID,
              keynoteID,
              strlen(keynoteID),
              kAutoGenerateReturnID, // Return ID for the created event
              kAnyTransactionID,     // Transaction ID for this event
              &eventToSend,          // Pointer to location for storing result
              &eventBuildError,      // Pointer to error structure
              "",                    // AEBuild format string describing the
              NULL                   // AppleEvent record to be created
        );
    if (err != noErr) {
        fprintf(stderr, "Failed to build Apple event (error %d).\n", (int)err);
        return err;
    }

    err = AESend(&eventToSend,
                 &eventReply,
                 kAEWaitReply,      // send mode (wait for reply)
                 kAENormalPriority,
                 kNoTimeOut,
                 nil,               // no pointer to idle function
                 nil);              // no pointer to filter function
    
    if (err != noErr)
        fprintf(stderr, "Failed to send Apple event (error %d).\n", (int)err);

    // Dispose of the send/reply descs
    AEDisposeDesc(&eventToSend);
    AEDisposeDesc(&eventReply);

    return err;
}