1

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.

1

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
    quit application "System Preferences"
    delay 1
end if
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.

  • Also 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.


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 to accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

0

Macroing this is a bit janky, but it's totally doable.

I'd recommend using Keyboard Maestro for this. It's sort of like Automator.... Not free, but it does have a trial and it's definitely worth it. You could do this same thing in Automator or Applescript too, but it's way simpler in KBM.

KBM has some great Actions when it comes to navigating gui:

  • Pause Until
    • The Pause Until action pauses until criteria for conditions are met.
  • Press a Button
    • The Press a Button action presses a named button in the front window.
  • Select or Show a Menu Item
    • The Select or Show a Menu Item action selects a menu item OR shows (opens) a menu in the main menubar.
  • Insert Text by Typing
    • The Insert Text by Typing action converts plain (simple) text into keystrokes and then types each of them individually. It only works with characters that can be typed on the keyboard with one or two keystrokes (eg Option-e e usually types é, and Keyboard Maestro can duplicate that typing).
  • Type a Keystroke
    • The Type Keystroke action lets you type a single keystroke, pretty much any kind of keystroke you can type on the keyboard.
  • Move or Click Mouse
    • The Move or Click Mouse action allows you to move, click or move and click the mouse using any mouse button, and optionally dragging.
    • This is a relatively small thing, but I think it's great that it can restore the mouse location after the action is completed. That option is a bit hidden though.

The steps to produce the action along with light explanations:

Picture of the macro steps (Link)

Not the fastest macro ever (~3seconds), but sure beats diving into the menus manually.

As you are making this macro, make sure to run the unfinished macro after every step to make sure everything is exactly as they should be.

  1. Action name: Activate a Specific Application
    • Activate: System Preferences
    • Opens up System Preferences

  2. Action name: Pause Until
    • New Condition: Menu Condition
    • A menu item: with this name Accessibility is enabled
    • This more or less makes sure the window is active and Accessibility is a menu item you can navigate to.

  3. Action name: Move a Window
    • Move to: →00
    • This makes sure that the preferences window is in your main screen. It's only important because if at any point you manually drag the window to your secondary screen, all the actions that rely on coordinates would fail without this and the next 'Move a Window action'.

  4. Action name: Select or Show a Menu Item
    • Select menu in: System Preferences
    • Menu Title: View
    • Menu Item Accessibility
    • You can also just click Menu ▾ on the top left of this action to choose the menu item from there, as long as System Preferences is open. That makes it super easy to simulate clicking any menu item.

  5. Action Name: Pause
    • Pause for : 1 seconds.
    • This is a bit of a mystery. I wanted to use pause until window title is 'Accessibility', which works if you go to the Accessibility page in System Preferences and check the action. KBM says the value is true when you're there. However, it kept failing when I actually ran the macro. I also tried the 'Pause Until Pixel Condition’ and that failed as well I guess the condition became true before any interaction was possible… The point of using the 'Pause Until' action is to make sure that whatever we want to do next actually triggers at the right moment. When you use a static pause or no pause at all, there is a chance that it occasionally takes longer than usual and the simulated keypress just goes into the ether and the macro gets stuck or worst case scenario: it actually does something totally different, like sends a missile warning alert to all Hawaiians or something. The few spots where I used a static pause should be fine since they are all in the same page of the same window so there shouldn't be any weird issues brought on by those, but if it doesn't do what it's supposed to do: increase the static delay. You may also want to add 'Pause' between some of the other actions that are not separated by a delay, if it doesn't seem to work. Slower machines typically require bigger delay.

  6. Action Name: Type a Keystroke
    • Simulate keystroke: Cmd+F
    • Click the Simulate keystroke input and press the shortcut keys.
    • If this window is already active, this sort of defaults the position to the search so the next keystroke goes to the right place

  7. Action name: Move a Window
    • Change Move to to Center
    • This makes sure all the actions using coordinates hit the right spots.

  8. Action Name: Type a Keystroke

    • Simulate keystroke: Tab
    • You can select it from the dropdown list or type it in.
    • Activates the list on the left side of System Preferences > Accessibility window.

  9. Action Name: Pause Until

    • New Condition: Pixel Condition
    • Click the Get
      • It'll give you 5 seconds to position your mouse on top of the color.
      • Make the window active and hover your mouse anywhere on top of the blue edge to get that color
      • enter image description here
    • This just makes sure the next action is triggered at the right time.

  10. Action Name: Type a Keystroke

    • Simulate keystroke: End
    • You can select it from the dropdown list or type it in.
    • Activates the list on the left side of System Preferences > Accessibility window.

  11. Action Name: Type a Keystroke

    • Simulate keystroke: Alt+Down Arrow
    • Click the Simulate keystroke input and press the shortcut keys.
    • This menu on the left can retain the last visited item next time you open it, so we do this just to make sure the first item is selected or else the next pause until could fail occasionally.
  12. Action Name: Pause Until

    • New Condition: Pixel Condition
    • Again the same thing as with the last Pause Until → Pixel Condition. Press the Get button, activate the Accessibility window and pick a color from the active item's background.
    • enter image description here
    • This just makes sure the next action is triggered at the right time.

  13. Action: Move or Click Mouse

    • Relative to the Absolute position
    • Click the gear menu on the top right corner of the action and select Restore Mouse Location.
    • Press the Get button and hover over the “Mouse & Trackpad”
    • I chose to use relative to the absolute position since the Pixel Conditions can't be relative to the current window... Doesn't really matter much.

    • enter image description here
  14. Action Name: Pause Until

    • New Condition: Pixel Condition
    • Again the same thing as with the last Pause Until → Pixel Condition. Press the Get button, activate the Accessibility window and pick a color from the active item's background.
    • enter image description here
    • This just makes sure the next action is triggered at the right time.

  15. Action: Move or Click Mouse

    • Relative to the Absolute position
    • Click the gear menu on the top right corner of the action and select Restore Mouse Location.
    • Press the Get button and hover over the Ignore built-in tackpad when mouse or wireless trackpad is present
    • I chose to use relative to the absolute position since the Pixel Conditions can't be relative to the current window... Doesn't really matter much.

    • enter image description here
  16. Action Name: Pause

    • Pause for .6 seconds
    • You may want to lengthen this if you feel like you can't quite see the value changing and you'd like to... This delay was added for that reason, but it does go by pretty fast. Try something like 1 second...

  17. Action Name: Quit a Specific Application
    • Quit: System Preferences.
    • You may want to disable this action for testing purposes.
  • You said, "I'm pretty sure the command line solutions are blocked by SIP.", well SIP has absolutely nothing whatsoever to do with why using defaults to modify a key's value in a .plist file fails to achieve the goal. The defaults command was rendered almost useless as of OS X 10.8 and later where major changes were made that broke the effective use of it as compared to older versions of OS X. It still can be used in some cases but not nearly as many as it used to be where it once use to take immediate effect without necessarily having to kill a process to get the change to take. – user3439894 Apr 9 '18 at 12:28
  • @user3439894, I'm guessing it doesn't work in this situation since you didn't post that as an answer? – Joonas Apr 9 '18 at 12:36
  • I didn't even try to use defaults in this use case. The point I was trying to make is, your statement I quoted in my previous comment is erroneous! SIP does not block the defaults command from taking action on .plist files in ~/Library/Preferences. You should read: About System Integrity Protection on your Mac – user3439894 Apr 9 '18 at 12:42
  • @user3439894, it's not that I didn't get what you said. You implied the command line option might still be on the table but didn't confirm if it actually was... I was focusing on finding a good answer to the question and you were focusing on telling me I was wrong in one of my statements. – Joonas Apr 9 '18 at 12:59
  • You said, "You implied the command line option might still be on the table but didn't confirm if it actually was...", I never implied anything, only made statements of fact. There was nothing to confirm as it's specific use was not explicitly relevant to the comment I made! With no disrespect intended, it appears your assumption that SIP is in play here shows you do not have a good handle on SIP or defaults. I too was focused on providing a good answer, which I believe I did by showing it can be done natively with no third-party anything needed, simply and easily using AS and UI Scripting. – user3439894 Apr 9 '18 at 13:39

You must log in to answer this question.

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