Progress: Now I'm able to open and close the Keyboard Viewer using the following applescript:
if application "System Preferences" is running then do shell script "killall 'System Preferences'"
repeat until application "System Preferences" is not running
delay 0.1
end repeat
tell application "System Preferences"
reveal anchor "Virtual_Keyboard" of pane "com.apple.preference.universalaccess"
end tell
tell application "System Events" to tell application process "System Preferences"
repeat until checkbox "Enable Accessibility Keyboard" of tab group 1 ¬
of group 1 of window "Accessibility" exists
delay 0.1
end repeat
set theValue to value of checkbox "Enable Accessibility Keyboard" of tab group ¬
1 of group 1 of window "Accessibility"
delay 0.1
if theValue = 1 then
set frontmost to true
repeat until frontmost
delay 0.1
end repeat
click checkbox "Enable Accessibility Keyboard" of tab group 1 of ¬
group 1 of window "Accessibility"
delay 0.1
if UI element "OK" of sheet 1 of window "Accessibility" exists then
click UI element "OK" of sheet 1 of window "Accessibility"
end if
else
click checkbox "Enable Accessibility Keyboard" of tab group 1 of ¬
group 1 of window "Accessibility"
end if
end tell