AppleScript to turn on the Accessibility Keyboard in High Sierra
Update Note: This answer was originally written prior to the release of macOS Mojave and as such to use it in macOS Mojave you'll need to change three lines of code.
Change:

select table 1 of scroll area 2
select row 16 of table 1 of scroll area 2
tell tab group 1

To:

select table 1 of scroll area 1
select row 16 of table 1 of scroll area 1
tell tab group 1 of group 1


The following example AppleScript code works for me under macOS High Sierra:
if running of application &quot;System Preferences&quot; then
    quit application &quot;System Preferences&quot;
    delay 1
end if
tell application &quot;System Preferences&quot;
    reveal pane id &quot;com.apple.preference.universalaccess&quot;
    delay 1
    tell application &quot;System Events&quot;
        tell window 1 of application process &quot;System Preferences&quot;
            select table 1 of scroll area 2
            delay 0.1
            select row 16 of table 1 of scroll area 2
            delay 0.1
            tell tab group 1
                click radio button &quot;Accessibility Keyboard&quot;
                delay 0.1
                click checkbox &quot;Enable Accessibility Keyboard&quot;
            end tell
        end tell
    end tell
    quit
end tell

In Script Editor, I saved example AppleScript code as an application, named Accessibility Keyboard.app, in the Applications folder.
Next, I added the Accessibility Keyboard.app to: System Preferences &gt; Security &amp; Privacy &gt; Privacy &gt; Accessibility
Now I can bring up the Accessibility Keyboard easily via Spotlight, or the Accessibility Keyboard.app can be dragged and dropped on the Dock so as to be launched for there.

Update:
My original example AppleScript code was geared at opening the Accessibility Keyboard, not closing it. As such, if it's open and the original script is run again it errors out. The following version of the example AppleScript code accounts for whether or not the Accessibility Keyboard it already shown and if so, closes it.
Note thought that while this does close the Accessibility Keyboard if it's showing, there is an added bounce to Dock Tile of System Preferences and is not and issue other then a secondary visual distraction.
Example AppleScript code:
if running of application &quot;System Preferences&quot; then
    quit application &quot;System Preferences&quot;
    delay 1
end if
tell application &quot;System Preferences&quot;
    reveal pane id &quot;com.apple.preference.universalaccess&quot;
    delay 1
    tell application &quot;System Events&quot;
        tell window 1 of application process &quot;System Preferences&quot;
            select table 1 of scroll area 2
            delay 0.1
            select row 16 of table 1 of scroll area 2
            delay 0.1
            tell tab group 1
                click radio button &quot;Accessibility Keyboard&quot;
                delay 0.1
                if value of checkbox &quot;Enable Accessibility Keyboard&quot; is 0 then
                    click checkbox &quot;Enable Accessibility Keyboard&quot;
                else
                    click checkbox &quot;Enable Accessibility Keyboard&quot;
                    delay 1
                    my clickOK()
                end if
            end tell
        end tell
    end tell
    quit
end tell

on clickOK()
    tell application &quot;System Events&quot; to click button &quot;OK&quot; of window 1 of application process &quot;System Preferences&quot;
end clickOK


Note that System Preferences does not need to be visible for this to work and why there is no activate command in the example AppleScript code. Additionally if System Preferences is already open, it is first closed before the rest of the code is processed. This is done for a couple of reasons, the first of which was already stated and secondly seeing the UI Events processed is a visual distraction and can be annoying.
Also note that the value of the delay commands may need to be adjusted for your system, and or additional delay commands may or may not be needed. Adjust values of and or add/remove the delay commands as appropriate.
Keep in mind that once the app is added to System Preferences &gt; Security &amp; Privacy &gt; Privacy &gt; Accessibility and modified thereafter, you'll need to uncheck it and recheck it for the new changes to be allowed to be processed.

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.