我想发送击键到OBS以触发场景更改。我已经通过AppleScript编写了一种方法来实现这一点:
+ (void)sendKeyWithControlDown:(NSString*)key afterMSDelay:(NSInteger)delay toOBSType:(OBSType)obsType completion:(void(^)(NSDictionary *error))completion {
NSString *appName = (obsType == OBSTypeOBS) ? @"OBS" : @"RPAN Studio";
NSString *source = [NSString stringWithFormat:@"tell application \"%@\" to activate \n tell application \"System Events\" to keystroke \"%@\" using control down", appName, key];
NSAppleScript *applescript = [[NSAppleScript alloc] initWithSource:source];
NSDictionary *dict;
[applescript executeAndReturnError:&dict];
completion(dict);
}字典返回一个错误1002,即System Events got an error: <my app> is not allowed to send keystrokes
我尝试了以下几点:
com.apple.security.temporary-exception.apple-events和Apple Events添加到应享权利文件中,每个文件都有一个真值Privacy - AppleEvents Sending Usage Description添加到应用程序的info.plist中,并提供了描述。这个应用程序在我第一次运行新的构建时要求我允许这样做,我同意,这个应用程序在System Preferences > Security & Privacy中显示在Accessibility和Automation部分。在这两个地方都有标记。我尝试过取消标记、re-ticking。
它已经成功了几次,但还不足以解释其停止的原因。在工作和停止工作之间,我没有做任何代码更改。
发布于 2020-10-30 20:57:37
它似乎取消和重新勾选系统首选项中的权限,而我忘了您实际上可以将它们从列表中删除。我认为它存储了另一个版本的权限,并且对我允许的应用程序感到困惑。在移除它并重新添加它之后,它起了作用。
https://stackoverflow.com/questions/64614663
复制相似问题