Is it possible to change the “Ignore built-in trackpad when mouse is present” setting with a keyboard shortcut

automatormouseterminaltrackpad

I like to use my MacBook with a USB mouse most of the time, and keep "Ignore built-in trackpad when mouse or wireless trackpad is present" option checked to avoid accidentally moving the cursor while typing. However, occasionally it's useful to switch it back on for certain tasks, and I'd like to be able to do this with a keyboard shortcut.

I've tried recording the process of switching it on/off with Automator, but when I copy the resulting script and run it, it gets as far as the Accessibility settings and then gives me a syntax error saying 'Can not click checkbox 3 of window "Accessibility" of application process "System Preferences"'.

I've also tried setting "USBMouseStopsTrackpad" in defaults to 0 and 1 in the terminal, but it doesn't seem to do anything. I can see this changing to 0 or 1 when I check/uncheck the box, so I'm fairly certain I've got the right option, but nothing happens when I change it.

Apologies if this is really obvious and I'm just not seeing it! I'm still not too familiar with this machine. I'm aware of this question:

Is it possible to switch off the trackpad in OS X with a keyboard shortcut

but I don't think it's a duplicate as I'm trying to do something slightly different.

Best Answer

This can be done natively with no third-party anything needed, simply and easily using AppleScript and UI Scripting.

The example AppleScript code can be implemented in a number of different ways, as a script, an AppleScript application, or as an Automator service , the latter of which can have a keyboard shortcut assigned to it.

Specifically how to implement as an Automator service has been covered more then enough times that a Google search should provide an answer on how to do that. I know I written directions for it more times than I can remember.

The following example AppleScript code works for me and toggles the "Ignore built-in trackpad when mouse or wireless trackpad is present:" check box:

if running of application "System Preferences" then
    try
        tell application "System Preferences" to quit
    on error
        do shell script "killall 'System Preferences'"
    end try
end if
repeat while running of application "System Preferences" is true
    delay 0.1
end repeat
tell application "System Preferences"
    reveal anchor "Mouse" of pane id "com.apple.preference.universalaccess"
    delay 1
    tell application "System Events"
        click checkbox 1 of group 1 of window 1 of application process "System Preferences"
    end tell
    quit
end tell
  • 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.

  • This was tested and works under macOS High Sierra; however, note that depending on the version of OS X/macOS you're running, the click checkbox ... line of code may need to be adjusted depending on the version of the OS.

For example, with macOS Catalina you'd need to use:

click checkbox 2 of tab group 1 of group 1 of window 1 of application process "System Preferences"


Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.