macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

dispatchRawAppleEvent:withRawReply:handlerRefCon:

アップルイベントを送信します
-(OSErr)dispatchRawAppleEvent:(const AppleEvent *)theAppleEvent:
                    withRawReply:(AppleEvent *)theReply:
                    handlerRefCon:(UInt32)handlerRefcon:

解説

アップルイベントを送信します。
他のアプリケーションにイベントを送るために使用することはできません。
アップルイベントを他のアプリケーションに送信するためにはCarbonフレークワークを利用する必要があります(10.2-10.3)

返り値

( OSErr )

エラーコード

引数

( const AppleEvent * )theAppleEvent

アップルイベント

( AppleEvent * )theReply

リプライ

( UInt32 )handlerRefcon

ハンドラ参照

クラス

NSAppleEventManager

Instance Methods

使用可能

10.0

参照

例文

#import "Controller.h"

@implementation Controller
-(void)awakeFromNib
{

aeMgr = [NSAppleEventManager sharedAppleEventManager];

[ aeMgr setEventHandler:self
        andSelector:@selector(handleAppleEvent:withReplyEvent:)
        forEventClass:kASAppleScriptSuite
        andEventID:kASCommentEvent 
        ];
NSLog([[aeMgr currentAppleEvent] description]);
}
- (IBAction)pushButton:(id)sender
{
  AppleEvent    event, reply;
  OSErr      err;
  OSType      adrFinder = 'XXXX';//
  FSRef      fileRef;
  AliasHandle    fileAlias = NULL;

  err = FSPathMakeRef([@"/" fileSystemRepresentation], &fileRef,NULL);
  if (err != noErr) return;

  err = FSNewAliasMinimal(&fileRef, &fileAlias);
  if (err != noErr) return;

  err = AEBuildAppleEvent(kASAppleScriptSuite, kASCommentEvent, typeApplSignature,&adrFinder, sizeof(adrFinder),
    kAutoGenerateReturnID, kAnyTransactionID, &event, NULL,"'----':alis(@@)", fileAlias);
  if (err != noErr) return;
     
aeMgr = [NSAppleEventManager sharedAppleEventManager];
[aeMgr dispatchRawAppleEvent:&event
        withRawReply:&reply
        handlerRefCon:nil
        ];
}

- (void)handleAppleEvent:(NSAppleEventDescriptor *)inEvent
    withReplyEvent: (NSAppleEventDescriptor *)outReplyEvent

{
NSLog(@"!!!");
}

@end