Skip to content

Instantly share code, notes, and snippets.

@ofenstichloch
Last active December 13, 2021 21:36
Show Gist options
  • Save ofenstichloch/1fff1d6ff00802a087be5f06f4a2e8e6 to your computer and use it in GitHub Desktop.
Save ofenstichloch/1fff1d6ff00802a087be5f06f4a2e8e6 to your computer and use it in GitHub Desktop.
Simple applescript to toggle the trackpad on a macbook on and off. This script uses the "Turn off Trackpad when USB Mouse is connected" feature of Mac OS. Tested on 10.12.6
tell application "System Events"
tell process "System Preferences"
try
set visible to false
end try
tell application "System Preferences"
delay 1
reveal pane id "com.apple.preference.universalaccess"
end tell
delay 1
get entire contents of window "Accessibility"
select row 15 of table 1 of scroll area 1 of window "Accessibility"
click checkbox 2 of tab group 1 of group 1 of window "Accessibility" of application process "System Preferences" of application "System Events"
end tell
end tell
quit application "System Preferences"
@Stevemoretz
Copy link

Thank you so much for me it was :

tell application "System Events"
	tell process "System Preferences"
		try
			set visible to false
		end try
		tell application "System Preferences" to reveal pane id "com.apple.preference.universalaccess"
		get entire contents of window "Accessibility"
		select row 14 of table 1 of scroll area 1 of window "Accessibility"
		click checkbox 2 of tab group 1 of group 1 of window "Accessibility" of application process "System Preferences" of application "System Events"
	end tell
end tell
quit application "System Preferences"

Need to be changed a little bit, here's how I found the gui names:

delay 5
tell application "System Events"
	tell front window of (first application process whose frontmost is true)
		set uiElems to entire contents
	end tell
end tell

@ofenstichloch
Copy link
Author

Thanks for the update. Ive updated and tested the script on MacOS 12.0.1. I had to change the row (14 -> 15) for Monterey and add a delay to make it more robust when loading the "Accessibility" tab is slow.

@Stevemoretz
Copy link

Thank you so much, I have Catalina 10.15.17 maybe that's why you need 15 and I need 14, anyways very useful I couldn't find a way to make it work other than messing around with the SQLite file which has the preferences stored in it, that delay also is a great idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment