Code to activate and deactivate trackpad


Does anyone have code to turn off and on the trackpad? I recently got a Magic Trackpad for my monitor and I'm wanting to have a touch bar button that turns on handoff my trackpad.


You don't need code for that, you can make use of the accessibility function in MacOS itself. Go to System Preferences -> Accessibility -> Pointer Control -> Alternative Control Methods... click on the Options button for Enable Mouse Keys

and tick both the options

Now any time you want to disable the trackpad, just press the option key on the keyboard 5 times in a row... do the same to enable it back.

oh cool! thanks. then I can make a touchbar button for this with key sequences, right?

when I activate mouse keys, some of the keyboard letters don't work. how do I fix it?

You can't :cry:

Because those keys now move your mouse cursor.

Hmm... perhaps this option might be better for you then?

I use that but if im not near my connected Magic Trackpad and I need to use my built in trackpad, I don't want to have to go to the Magic Trackpad to turn it off, id rather have a button to do that on the touchbar.

In that case maybe a button on the touchbar that executes a script to click/unclick that setting for you? :slight_smile:

tell application "System Preferences"
	reveal anchor "Mouse" of pane id ""
	delay 1
	tell application "System Events"
		click checkbox 2 of tab group 1 of group 1 of window 1 of application process "System Preferences"
	end tell
end tell
1 Like

thanks heaps this worked

glad it worked for you!

1 Like