I would like to display and hide the Keyboard Viewer using a shortcut.
- Is there a way to display the Keyboard Viewer via a keyboard shortcut?
- Is there a way to automatically display the Keyboard Viewer once I switch to a specific language?
I would like to display and hide the Keyboard Viewer using a shortcut.
You can launch the Keyboard Viewer with a shortcut by using Automator and the OS X Services functionality.
The Keyboard Viewer program lives at /System/Library/Input Methods/KeyboardViewer.app
(in versions prior to Lion, it may be at /System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/KeyboardViewerServer.app
). You open it with a hotkey by using Automator to create a simple launcher service.
Add the Run AppleScript action to your workflow, and replace the text with the following lines:
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"
A couple notes:
repeat
loop checks every 5 seconds if Keyboard Viewer has any open windows, and if not, quits the process.KeyboardViewer
with KeyboardViewerServer
. I don't have anything pre-Lion handy to test this (if someone else could report back in the comments, that would be great./System/Library/Input Methods/KeyboardViewer.app
doesn't exist on Catalina. I opened all of the applications in /System/Library/Input Methods
and none of them opened the keyboard viewer. Any ideas?
Commented
Jan 2, 2020 at 10:31
It's dead in Catalina - no app called KeyboardViewer any longer.
Instead, use the Accessibility options in System Preferences and toggle everything else off so the Accessibility options shortcut (⌘ + ⎇ + F5) only turns the Accessibility Keyboard on and off. Of course, if you need the other options and to see the keyboard, you're boned. Thanks Apple!!
I have found a way through BetterTouchTool to do the following :
Platform : rMBP Mountain Lion OSX 10.8
Activate Keyboard Viewer by a shortcut
Now you have a keyboard shortcut to activate the viewer without an additional script.
HOWEVER, I noticed that pressing the red X button does not actually quit the application, which means that the keyboard viewer will only be activated once. So you need to create a script to quit the program.
To fix this problem :
Close Keyboard Viewer by another keyboard shortcut
quit application "KeyboardViewer"
You now have a way to quit the KeyBoard viewer for good once its activated. Use it instead of the red X button. Until I figure out why the keyboard viewer does not fully quit when you press the X button, this should be your solution.
EDIT
I have figured out a way to TOGGLE the keyboard viewer !!
TOGGLE KEYBOARD VIEWER by one keyboard shortcut
same process as before but the code is changed :
if application "KeyboardViewer" is running then quit application "KeyboardViewer" else activate application "KeyboardViewer" end if
Now the Keyboard Viewer is toggled and you dont even need to assign multiple shortcuts !
Link for AppleScript
I uploaded the app online for faster access rather than doing the whole coding steps above (just activate this app through BetterTouchTool) However, since im not an identified publisher, your OS may block running this app, depending on your security preferences. So if you prefer to not run apps from unidentified publishers, just follow the steps above to create your own app !
Link to file : https://www.box.com/s/e2461c91e30e0af025e7
Hope it helps anyone as it helped me :)
Glad I found this thread. Based on the answers above, I made an Alfred extension script that toggles Keyboard Viewer.
https://dl.dropbox.com/u/29440342/linkedFiles/Keyboard%20Viewer.alfredextension
It provides an alfred keyword "kv" that toggles Keyboard Viewer on and off, by running the following applescript:
-- 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
I left an alternative implementation commented out, in case I experience performance problems that it was meant to avoid.
The Extra Scripts Plugin of Quicksilver offers this functionality by providing Show Keyboard Viewer.scpt.
Also, when you create a Quicksilver Trigger for Show Keyboard Viewer.scpt with the action Run, then you get the global Keyboard Viewer hotkey.
Here's the source of the script:
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
If KeyboardViewer is opened with an AppleScript or with open
and the main window is closed, the Keyboard Viewer process stays open and keeps using about 0-20% CPU.
This would also work after the main window has been closed by clicking the close button:
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
If Keyboard Viewer is opened with AppleScript or open -a KeyboardViewer
and the main window is closed, the process stays open and keeps using about 0-15% CPU. It doesn't happen when selecting Show Keyboard Viewer from the input menu. So a better option might be to click the menu item:
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
Both scripts require access for assistive devices to be enabled in the accessibility preference pane.
The selected answer does not work on Catalina. This one does:
activate application "System Preferences"
tell application "System Preferences"
reveal anchor "Virtual_Keyboard" in pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
tell process "System Preferences"
delay 1
set theCheckbox to checkbox "Enable Accessibility Keyboard" of tab group 1 of group 1 of window 1
if (value of theCheckbox as boolean) then
click theCheckbox
key code 36 -- Handle the confirmation dialog
else
click theCheckbox
end if
delay 1
end tell
end tell
tell application "System Preferences" to quit
It's not a single-stroke shortcut, but a "non-mousing" solution is Fn+Ctrl+F8 to set focus on the "Status menu" icons on the right side of the menu bar. (Section 4)
Arrows will navigate you to the Keyboard Preferences icon and the Show/Hide options. When you enter Fn+Ctrl+F8 the icon to the furthest left side of the "Status menu" icons which are on the right half of the menu bar will get highlighted. Once it is selected, then use the Right Arrow → to navigate to the one you want. Use the Down Arrow ↓ to open the menu and select the option you want. Note that the Option key will make different menu options available in some of the "status menus".
Of note, Fn+Ctrl+F2 will activate the Apple menu icon on the left hand side. From there the Right Arrow → will give you access to the Application menu. These options are available in System Preferences >> Keyboard >> Shortcuts::Keyboard:
Depending on how you have your Function keys configured, the Fn is optional.
In macOS Sierra you can also use Siri to help with this. Invoke Siri with whichever keyboard shortcut you choose from System Preferences >> Siri::Keyboard Shortcut, for example Option+Spacebar
...then say "Turn on the Keyboard Viewer"
...and voila:
Unfortunately, Siri will not close the Keyboard Viewer, nor will Command⌘+w
It is not a shortcut, but working for me. First click on Show keyboard viewer. After when you go with the mouse to the corner, A little triangle showing. When it is ready, the keyboard viewer hide. The next it is showing.
Here is a little video about it: https://dai.ly/x7t7x60
you can do everything by Automator:
next part is to close keyboard:
choose "other" and navigate to KeyboardViewer file in /System/Library/Input Methods
Save with an name like "quit keyboard". test it.
now you will have two files one for open, one for close.
all you need is associate your mouse buttons to launch these two files!
for example, i`m using Microsoft Bluetooth Notebook Mouse 5000 and it
work great for me in 10.9.1
Activity Monitor, KeyboardViewer.app launches from
Finder location: /System/Library/Input Methods/KeyboardViewer.app.
Normal use: open from Menu Bar, close from mouse hover to view window buttons where (x) close button can be clicked. To enable Menu Bar panel, System Preferences, Keyboard, Keyboard tab, select Show Keyboard and Emoji Viewers in menu bar.
KeyboardViewer applet exhibits restrictive behaviors.
The following Automator script can be saved as an application to open-close KeyboardViewer.app with a single click (Activity Monitor also shows this open-close activity), and it works well when placed in Dock.
Automator: New, Application, Run AppleScript, save this script
-- 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
Unfortunately, this does not add a keyboard shortcut. However, it does offer a one-click workaround. There may be some way to add a keyboard shortcut using Automator. A general shortcut script looks something like this (but not sure how to incorporate).
tell application "System Events"
set application "KeyboardViewer" to keystroke "K" using control down
end tell
(macOS Sierra 10.12.6 on MP 6,1)