使用 ScriptingBridge 表达范围(或切片)

发布于 2024-10-17 13:41:57 字数 631 浏览 6 评论 0原文

我正在尝试使用 Scripting Bridge 在 Objective-C 中表达切片(“通过 AppleScript”)。 示例代码在 iWorks Pages 中进行选择。 AppleScript 代码如下所示

 tell application "Pages"
     tell document 1
         select (characters 8 thru 14)
     end tell
 end tell

,Objective-C 代码在这里。我需要的是一种在 Objective-C 中表达(字符 8 到 14)的方式。

PagesApplication *app;
app = [SBApplication applicationWithBundleIdentifier:@"com.apple.iWork.Pages"];
SBElementArray *docs = [app documents];
PagesDocument *doc = [docs objectAtIndex:0];

// now we need to express
// "select (characters 8 thru 14)" in obj-c

// ??

感谢您的任何帮助。比约恩

I'm trying to express a slice ("thru in AppleScript") in Objective-C using Scripting Bridge.
The example code is making a selection in iWorks Pages.
The AppleScript code looks like this

 tell application "Pages"
     tell document 1
         select (characters 8 thru 14)
     end tell
 end tell

and the Objective-C code is here. What I need is a way of expressing (characters 8 thru 14) in Objective-C.

PagesApplication *app;
app = [SBApplication applicationWithBundleIdentifier:@"com.apple.iWork.Pages"];
SBElementArray *docs = [app documents];
PagesDocument *doc = [docs objectAtIndex:0];

// now we need to express
// "select (characters 8 thru 14)" in obj-c

// ??

Thankful for any help. Björn

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2024-10-24 13:41:57

我必须使用低级别的 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);

I had to use low level AppleEvents. Did monitor the Apple Events from the command line.
Here is a code that does it:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文