How do I activate Mouse Keys with an apple script or the command line?
I was also not able to automate enabling &quot;Mouse Keys&quot; by key stroking the &quot;Option&quot; key 5 times. However, I was able to figure out a workaround using this... keystroke &quot;z&quot; using {command down, option down, control down}.  On OS Catalina, as you can see in the following image, using this keyboard shortcut will open the Accessibility Options overlay window.  And once this window is open, you can set Mouse Keys to On or Off.

Here is the Accessibility Options overlay window which opens when using that keyboard shortcut.

Here is the AppleScript code I created which automates the process of enabling Mouse Keys.
tell application &quot;System Events&quot; to tell application process &quot;UniversalAccessControl&quot;
    keystroke &quot;z&quot; using {command down, option down, control down}
    delay 3
    click checkbox &quot;Enable Mouse Keys&quot; of window &quot;Accessibility Options&quot;
    delay 1
    click button &quot;Done&quot; of window &quot;Accessibility Options&quot;
end tell

I saved my version of the code as a .scpt file and added it to the Script menu in the menu bar for testing purposes. Using Automator, you can easily create a new &quot;Quick Action&quot; and add the AppleScript code, save the file then in System Preferences, you can create a keyboard shortcut for the file.
The following GIF demonstrates the process.

————————
If the entire process I just mentioned does not work for you, this following code may do the trick.
tell application &quot;System Events&quot;
    keystroke &quot;z&quot; using {command down, option down, control down}
    delay 3
    repeat 4 times
        key code 48 -- Tab Key
        delay 1.5
    end repeat
    key code 49 -- Space Key
    delay 1
    key code 36 -- Return Key
end tell