I'm running Mac OS X 10.7.2. Is there a way to run an AppleScript or terminal command that quickly turns on or off the "mouse keys" feature under the Universal Access tab? Ideally I'm looking for a solution that doesn't involve GUI scripting the System Preferences app, although that would be slightly better than nothing.

I've explored defaults write com.apple.universalaccess useMouseKeysShortcutKeys 1 and various other forms of that statement, but to no avail.


2 Answers 2


Here's the GUI scripting solution:

tell application "System Preferences"
    reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
    tell application "System Events"
        tell process "System Preferences"
            tell first window
                tell first tab group
                    tell radio group 1
                        if value of radio button 1 is 1 then
                            # enabled, so disable
                            click radio button 2
                            # disabled, so enable
                            click radio button 1
                        end if
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

It will launch System Preferences if required, but doesn't show the window and quits it afterwards, so from a UI POV, it at least doesn't show the window.

You can change the persistent setting on which the System Preferences configuration is based using the following commands:

defaults write ~/Library/Preferences/com.apple.universalaccess mouseDriver -bool YES
defaults write ~/Library/Preferences/com.apple.universalaccess mouseDriver -bool NO

Unfortunately, this only changes the configuration file and does not apply the changes to the running system.

While you can programmatically press Option keys using AppleScript, like the following:

tell application "System Events"
    key down option
    key up option
end tell

The press Option five times to toggle setting is at a higher level and doesn't get triggered by this. While all regular Option key presses are ignored after you only run key down option, you can still toggle Mouse Keys.

Debugging System Preferences while changing the setting shows calls to LaunchUAServerIfNeeded and UAMouseKeysSetEnabled in the private UniversalAccessCore framework. Unless we reverse engineer that framework and write our own binaries, I don't think we'll get a proper programmatic way to do this.

  • A phenomenal answer that only got better with the edit. Well done!
    – Daniel
    Commented Feb 10, 2012 at 23:10
  • how do you find out what the anchors are called? I guessed 'Keyboard' and 'Hearing' but I can't seem to guess what the anchor name for the Seeing tab should be. It's not Seeing, Sight, Vision.... What I'm really curious about is how to find them, without guessing.
    – user54823
    Commented Aug 9, 2013 at 22:02

Can't you use keystroke scripting in AppleScript for this?

Something along the lines of:

tell application "System Events"
    repeat 5 times
    //any of these should work
    key option
    key code 58
    key code option
    //I do not know if this works
    keystroke option
end tell
  • No, sadly, as far as I can tell, option is a modifier, not a scriptable keystroke.
    – Daniel
    Commented Feb 10, 2012 at 22:31
  • @Daniel The commands would be key down option and key up option, but don't work, even with delay 0.1 between each. Commented Feb 10, 2012 at 22:39
  • @Daniel Did you try it?
    – daviesgeek
    Commented Feb 10, 2012 at 22:40
  • 1
    I did. Didn't trigger the switch when run. Be careful to never mismatch a pair of these when you try. AFAIK it's impossible to release a key pressed this way unless with the correct key up. Commented Feb 10, 2012 at 22:45
  • Yes I tried and no, it doesn't work. :-(
    – Daniel
    Commented Feb 10, 2012 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .