Is it possible to change the "Ignore built-in trackpad when mouse is present" setting with a keyboard shortcut?
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 additionaldelay
commands may or may not be needed. Adjust values of and or add/remove thedelay
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.
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.
- Action name:
Activate a Specific Application
- Activate:
System Preferences
Opens up System Preferences
- Activate:
- 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.
- New Condition:
- Action name:
Move a Window
- Move to: →
0
↓0
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'.
- Move to: →
- 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.
- Select menu in:
- 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.
- Pause for :
- 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
- Simulate keystroke:
- Action name:
Move a Window
- Change
Move to
toCenter
This makes sure all the actions using coordinates hit the right spots.
- Change
-
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.
- Simulate keystroke:
-
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
This just makes sure the next action is triggered at the right time.
- New Condition:
-
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.
- Simulate keystroke:
-
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.
- Simulate keystroke:
-
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.
This just makes sure the next action is triggered at the right time.
- New Condition:
-
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.
- Relative to the
-
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.
This just makes sure the next action is triggered at the right time.
- New Condition:
-
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.
- Relative to the
-
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...
- Pause for
- Action Name:
Quit a Specific Application
- Quit:
System Preferences
. - You may want to disable this action for testing purposes.
- Quit:
I can't comment on @user3439894's answer due to insufficient reputation, but the correct line for OS X Catalina is:
click checkbox 2 of tab group 1 of group 1 of window 1 of application process "System Preferences"
Note the "... of tab group 1 ..." bit, which is now necessary.