这在Apple Script应用程序中运行良好:
tell application "System Events" to key code 124 using command down但在NSAppleScript中,它会在“关键代码”上出错。引号被正确地转义,几种不同的语法都做了同样的事情。在应用程序中有前面的东西来激活接收击键的应用程序,但在项目中不需要这些东西,如果它在那里,它就会被编译,所以很明显NSAppleScript正在拿起字典。我被难住了。
发布于 2012-11-28 12:46:13
我想通了。应用程序已使用跨脚本权限进行沙箱保护,没有系统事件应用程序的捆绑ID。
发布于 2012-11-28 07:16:36
我可以毫无错误地运行这段代码。result和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);https://stackoverflow.com/questions/13590323
复制相似问题