Answers:
您可以使用Automator和OS X Services功能以快捷方式启动Keyboard Viewer。
Keyboard Viewer程序位于/System/Library/Input Methods/KeyboardViewer.app(在Lion之前的版本中,它可能位于/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app)。通过使用Automator创建简单的启动器服务,可以通过热键打开它。
将“ 运行AppleScript”操作添加到您的工作流中,并将文本替换为以下行:
if application "KeyboardViewer" is running then
quit application "KeyboardViewer"
end if
activate application "KeyboardViewer"
-- wait until the window has been closed, then end the KeyboardViewer process
set numberOfWindows to 1
repeat until numberOfWindows = 0
delay 5
tell application "System Events"
tell process "KeyboardViewer"
set numberOfWindows to count windows
end tell
end tell
end repeat
quit application "KeyboardViewer"
几个注意事项:
repeat循环每5秒检查一次Keyboard Viewer是否有打开的窗口,如果没有,则退出该窗口。处理。KeyboardViewer用KeyboardViewerServer。我在Lion之前没有任何方便的工具可以对此进行测试(如果其他人可以在评论中进行举报,那将很棒。/System/Library/Input Methods/KeyboardViewer.app卡塔琳娜州不存在。我打开了所有应用程序/System/Library/Input Methods,但没有一个打开键盘查看器。有任何想法吗?
该额外的脚本插件的水银提供有这项功能显示键盘Viewer.scpt。
同样,当您通过“ 运行 ”操作为“ Show Keyboard Viewer.scpt”创建Quicksilver触发器时,会得到全局的Keyboard Viewer热键。
这是脚本的来源:
property theApplication : "KeyboardViewer"
property thePath : "/System/Library/Input Methods/KeyboardViewer.app"
set HFSPath to ((POSIX file thePath) as string)
tell application "System Events" to ¬
set isRunning to 0 < (count (application processes whose name is theApplication))
if isRunning then
tell application HFSPath to quit
else
ignoring application responses
tell application HFSPath to activate
end ignoring
end if
如果使用AppleScript或使用AppleScript打开KeyboardViewer,open并且关闭了主窗口,则Keyboard Viewer进程将保持打开状态并使用大约0-20%的CPU。
很高兴我找到了这个主题。基于上面的答案,我制作了一个Alfred扩展脚本来切换Keyboard Viewer。
https://dl.dropbox.com/u/29440342/linkedFiles/Keyboard%20Viewer.alfredextension
它提供了一个alfred关键字“ kv”,可通过运行以下小程序来打开和关闭键盘查看器:
-- adapted from http://apple.stackexchange.com/a/62532
if application "KeyboardViewer" is running then
quit application "KeyboardViewer"
else
activate application "KeyboardViewer"
end if
(*
-- adapted from http://apple.stackexchange.com/a/59986
tell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 where description is "text input") of menu bar 1
click
click (menu item 1 where title ends with "Keyboard Viewer") of menu 1
end tell
end tell
*)
-- icon ripped from osx /System/Library/PreferencePanes Keyboard.prefPane/Contents/Resources/Keyboard.icns
如果我遇到了本来可以避免的性能问题,则我将另一种实现注释掉了。
我已经找到了一种通过BetterTouchTool执行以下操作的方法:
平台:rMBP Mountain Lion OSX 10.8
通过快捷方式激活Keyboard Viewer
现在,您可以使用键盘快捷键来激活查看器,而无需其他脚本。
但是,我注意到按下红色的X按钮实际上并没有退出该应用程序,这意味着键盘查看器只会被激活一次。因此,您需要创建一个脚本来退出程序。
要解决此问题:
通过另一个键盘快捷方式关闭Keyboard Viewer
quit application "KeyboardViewer" 现在,一旦激活它,您就可以永久退出KeyBoard查看器。用它代替红色的X按钮。直到我弄清楚了为什么按下X按钮时键盘查看器没有完全退出,这才是您的解决方案。
编辑
我想出了一种切换键盘查看器的方法!
通过一个键盘快捷键切换键盘查看器
与以前相同的过程,但是代码已更改:
if application "KeyboardViewer" is running then quit application "KeyboardViewer" else activate application "KeyboardViewer" end if
现在,键盘查看器已切换,您甚至不需要分配多个快捷键!
AppleScript的链接
我在线上载该应用程序是为了更快地访问该应用程序,而不是执行上面的整个编码步骤(只需通过BetterTouchTool激活此应用程序即可)。但是,由于不是确定的发布者,因此您的操作系统可能会阻止运行此应用程序,具体取决于您的安全偏好。因此,如果您不想运行来自身份不明的发行商的应用程序,只需按照上述步骤创建自己的应用程序即可!
链接到文件:https : //www.box.com/s/e2461c91e30e0af025e7
希望它能帮助任何人,因为它对我有帮助:)
通过单击关闭按钮关闭主窗口后,这也将起作用:
if application "KeyboardViewer" is running then
tell application "System Events" to number of windows of process "KeyboardViewer"
if result is 0 then
quit application "KeyboardViewer"
delay 0.1
launch application "KeyboardViewer"
else
quit application "KeyboardViewer"
end if
else
launch application "KeyboardViewer"
end if
如果使用AppleScript或打开了Keyboard Viewer或open -a KeyboardViewer关闭了主窗口,则该进程保持打开状态并继续使用大约0-15%的CPU。从输入菜单中选择“显示键盘查看器”时,不会发生这种情况。因此,更好的选择可能是单击菜单项:
tell application "System Events" to tell process "SystemUIServer"
tell (menu bar item 1 where description is "text input") of menu bar 1
click
click (menu item 1 where title ends with "Keyboard Viewer") of menu 1
end tell
end tell
这两个脚本都要求在辅助功能首选项窗格中启用辅助设备的访问权限。
这不是一个单一的行程快捷,而是一种“非鼠标移动”解决方案Fn+ Ctrl+ F8将焦点设置在“ 状态菜单菜单栏右侧的”图标。(第4节)
箭头会将您导航到“键盘偏好设置”图标和“显示/隐藏”选项。当你进入Fn+ Ctrl+ F8的图标的“状态菜单”图标,这是菜单栏的右半边最远的左侧将得到凸显。选择之后,请使用Right Arrow →导航至所需的位置。使用Down Arrow ↓打开菜单,然后选择所需的选项。请注意,该Option键将在某些“状态菜单”中提供不同的菜单选项。
值得注意的是,Fn+ Ctrl+ F2将激活左边的苹果菜单图标。从那里Right Arrow →可以访问“应用程序”菜单。这些选项位于系统偏好设置>>键盘>>快捷方式::键盘中:
根据您配置功能键的方式,Fn可选。
在macOS Sierra中,您还可以使用Siri来解决此问题。使用从系统偏好设置>> Siri :: Keyboard快捷方式中选择的任意键盘快捷方式调用Siri,例如Option+Spacebar
...然后说“打开键盘查看器”
...还有瞧:
不幸的是,Siri不会关闭Keyboard Viewer,也不会Command⌘+w
您可以通过Automator进行所有操作:
下一部分是关闭键盘:
选择“其他”并导航到/ System / Library / Input Methods中的KeyboardViewer文件
用“退出键盘”之类的名称保存。测试一下。
现在您将拥有两个文件,一个用于打开,一个用于关闭。
您所需要做的就是关联鼠标按钮以启动这两个文件!
例如,我使用Microsoft蓝牙笔记本鼠标5000及其它
在10.9.1中对我来说很棒
活动监视器,KeyboardViewer.app从以下位置启动
Finder位置: / System / Library / Input Methods / KeyboardViewer.app。
正常使用:从菜单栏打开,从鼠标悬停关闭以查看窗口按钮,其中可以单击(x)关闭按钮。要启用“ 菜单栏”面板,“ 系统偏好设置”,“ 键盘”,“ 键盘”选项卡,请选择“在菜单栏中显示键盘和表情符号查看器”。
KeyboardViewer小程序表现出限制性行为。
只需单击一下,即可将以下Automator脚本另存为应用程序,以打开-关闭 KeyboardViewer.app (“活动监视器”也显示此打开-关闭活动),并且将其放在Dock中时效果很好。
自动化器:新建,应用程序,运行AppleScript,保存此脚本
-- see above post, Render
on run {input, parameters}
if application "KeyboardViewer" is running then
quit application "KeyboardViewer"
else
activate application "KeyboardViewer"
end if
return input
end run
-- icon /System/Library/PreferencePanes Keyboard.prefPane/Contents/Resources/Keyboard.icns
不幸的是,这并没有添加键盘快捷键。但是,它确实提供了一键解决方法。可以使用某种方式使用Automator添加键盘快捷键。一般的快捷方式脚本如下所示(但不确定如何合并)。
tell application "System Events"
set application "KeyboardViewer" to keystroke "K" using control down
end tell
(MP 6,1上的macOS Sierra 10.12.6)