我不得不使用低级别的 AppleEvents。是否从命令行监视 Apple 事件。这是执行此操作的代码:
AppleEvent eventToSend, eventToReceive;
OSStatus err;
AEBuildError buildError;
char *bundleID = "com.apple.iWork.Pages";
eventToSend.descriptorType = 0;
eventToSend.dataHandle = NULL;
eventToReceive.descriptorType = 0;
eventToReceive.dataHandle = NULL;
err = AEBuildAppleEvent(kAEMiscStandards,
kAESelect,
typeApplicationBundleID,
bundleID,
strlen(bundleID),
kAutoGenerateReturnID,
kAnyTransactionID,
&eventToSend,
&buildError,
"'----':'obj '{form:rang, want:type('cha '), seld:'rang' {"
"star:'obj '{form:indx, want:type('cha '), seld:long(@), from:ccnt()},"
"stop:'obj '{form:indx, want:type('cha '), seld:long(@), from:ccnt()}},"
"from:'obj '{form:indx, want:type(docu), seld:long(1), from:()}}", 8, 14);
if (err != noErr) {
NSLog(@"failed to build Apple Event. Error code %d at pos %d\n", buildError.fError, buildError.fErrorPos);
exit(1);
}
err = AESendMessage(&eventToSend, &eventToReceive, kAEWaitReply, kAEDefaultTimeout);
if (err != noErr) {
NSLog(@"failed to send Apple Event\n");
exit(1);
}
/* deallocate memory */
AEDisposeDesc(&eventToReceive);
AEDisposeDesc(&eventToSend);