【发布时间】:2020-02-19 11:41:51
【问题描述】:
我想在 macOS APP 上通过 NSAppleScript 启动屏幕(虚拟)键盘。
以下代码在 macOS Catalina (10.15) 之前可以正常工作。都需要
允许。
NSString *theApplication = @"\"KeyboardViewer\"";
NSString *thePath = @"\"/System/Library/Input Methods/KeyboardViewer.app\"";
NSString *source = [NSString stringWithFormat:@"set HFSPath to ((POSIX file %@) as string)\n\
tell application \"System Events\" to ¬\n\
set isRunning to 0 < (count (application processes whose name is %@))\n\
if isRunning then\n\
tell application HFSPath to quit\n\
else\n\
ignoring application responses\n\
tell application HFSPath to activate\n\
end ignoring\n\
end if",thePath,theApplication];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source];
NSDictionary *dict = nil;
[script executeAndReturnError:&dict];
我收到一条错误消息(找不到文件「Macintosh HD:System:Library:Input Methods:KeyboardViewer.app)
我该如何解决?
【问题讨论】:
-
他们有一个新的应用程序 /System/Library/Input Methods/Assistive Control.app - 但您似乎无法直接启动它。它被配置为作为 LaunchAgent 启动。不知道如何以编程方式触发它。
-
我刚刚在这里发布了一个类似问题的答案:stackoverflow.com/questions/58488965/…
标签: objective-c macos keyboard macos-sierra macos-catalina