But this does not work on MacOs 13, 14 and 15:
import os
cmd = 'open -a KeyboardViewer'
os.system(cmd)
I had to use the following apple script can do this:
tell application "System Settings"
activate
end tell
do shell script "open 'x-apple.systempreferences:com.apple.preference.universalaccess?Keyboard'"
set endDate to (current date) + 5.0
repeat
try
tell application "System Events"
click checkbox 1 of group 3 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Keyboard" of application process "System Settings"
end tell
exit repeat
on error errorMessage
if ((current date) > endDate) then
error errorMessage
end if
end try
end repeat
tell application "System Settings"
quit
end tell
I wonder if there is an easier way to do this. I would be too much grateful for any help!