【问题标题】:Simple system events AppleScript won't work in NSAppleScript简单的系统事件 AppleScript 在 NSAppleScript 中不起作用
【发布时间】:2012-11-28 13:16:24
【问题描述】:

这在 Apple Script 应用程序中运行良好:

tell application "System Events" to key code 124 using command down

但在 NSAppleScript 中,“关键代码”会出错。引号被正确转义,几种不同的语法都做同样的事情。应用程序中有前面的东西来激活接收击键的应用程序,但项目中不需要,如果它在那里,它会编译,所以很明显 NSAppleScript 正在拾取字典。我难住了。

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    想通了。应用程序是具有跨脚本权利的沙盒,系统事件应用程序没有捆绑 ID。

    【讨论】:

      【解决方案2】:

      我可以毫无错误地运行此代码。结果和errorDict都记录为null,所以没有问题。你一定有其他问题...不是applescript。

      NSString* cmd = @"tell application \"System Events\" to key code 124 using command down";
      NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:cmd];
      NSDictionary* errorDict = nil;
      NSAppleEventDescriptor* result = [theScript executeAndReturnError:&errorDict];
      [theScript release];
      NSLog(@"result: %@", result);
      NSLog(@"error: %@", errorDict);
      

      【讨论】:

      • 代码与您的相同,但对于变量名称,我从调试器得到的是:2012-11-28 11:25:50.325 **********[10521:303] script = tell application "System Events" to key code 124 using command down 2012-11-28 11:25:50.817 **********[10521:303] NSAppleScriptErrorBriefMessage = A identifier can’t go after this property. 2012-11-28 11:25:50.817 **********[10521:303] NSAppleScriptErrorNumber = -2740 2012-11-28 11:25:50.818 **********[10521:303] NSAppleScriptErrorRange = NSRange: {36, 8} 计数字符,它将“关键代码”标记为有问题的标识符
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      相关资源
      最近更新 更多