Enable screen zoom via terminal
On my system, there are four .plist
files in ~/Library/Preferences/
that get modified when those two checkboxes are checked/unchecked:
com.apple.AppleMultitouchTrackpad.plist
com.apple.driver.AppleBluetoothMultitouch.trackpad.plist
com.apple.symbolichotkeys.plist
com.apple.universalaccess.plist
While one could take the steps to see which keys get added/modified/deleted and could write a script to using defaults
1 to change the appropriate keys in these files nonetheless, it would just be easier to use AppleScript to do it in System Preferences, if automating it is what you want.
-
In Terminal, use the following compound command to create the file and open it:
touch togzoom; open togzoom
Copy and paste the example AppleScript code, shown further below, into the opened
togzoom
file.Save and close the file.
-
Make the file executable:
chmod u+x togzoom
I used togzoom
for: [tog]gle zoom
NOTE: This will also require giving Terminal accessibility privileges for this to work properly.
You can now use it from the directory it's in using ./togzoom
otherwise /path/to/togzoom
; however, it's best if you place in into a directory that's within your PATH
statement. Then it can be used from anywhere by just togzoom
, (or whatever you actually named the executable).
The following example AppleScript code was tested and works for me, as coded, on macOS High Sierra and macOS Mojave; however, a minor change is needed for macOS Mojave and is noted in the paragraph after the code.
Example AppleScript code:
#!/usr/bin/osascript
if running of application "System Preferences" then
try
quit application "System Preferences"
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" to ¬
reveal anchor "Seeing_Zoom" of ¬
pane id "com.apple.preference.universalaccess"
tell application "System Events" to tell ¬
application process "System Preferences" to tell ¬
window "Accessibility"
repeat until exists checkbox "Use keyboard shortcuts to zoom"
delay 0.1
end repeat
set UKSTZ to (value of checkbox "Use keyboard shortcuts to zoom" as boolean)
set USGWMKTZ to (value of checkbox "Use scroll gesture with modifier keys to zoom:" as boolean)
if UKSTZ and USGWMKTZ then
click checkbox "Use keyboard shortcuts to zoom"
click checkbox "Use scroll gesture with modifier keys to zoom:"
set theMessage to " The target Zoom checkboxes are now not checked."
else if not UKSTZ and not USGWMKTZ then
click checkbox "Use keyboard shortcuts to zoom"
click checkbox "Use scroll gesture with modifier keys to zoom:"
set theMessage to " The target Zoom checkboxes are now checked."
else if UKSTZ and not USGWMKTZ then
click checkbox "Use keyboard shortcuts to zoom"
set theMessage to " The target Zoom checkboxes were out of sync and are now not checked." & ¬
linefeed & " Run again to check the target Zoom checkboxes..."
else if not UKSTZ and USGWMKTZ then
click checkbox "Use scroll gesture with modifier keys to zoom:"
set theMessage to " The target Zoom checkboxes were out of sync and are now not checked." & ¬
linefeed & " Run again to check the target Zoom checkboxes..."
end if
delay 0.1
end tell
quit application "System Preferences"
return theMessage
To use the example AppleScript code in macOS Mojave, make the following change to the code shown above:
Change:
window "Accessibility"
To:
group 1 of window "Accessibility"
What this script does:
- It toggles the state of the two target checkboxes.
- If the target checkboxes are out of sync, it un-checks the one checked and returns a message.
The following shows the command run three times in Terminal to show its output. For demonstration purposes, in System Preferences > Accessibility > Zoom, one of the target checkboxes is checked and the other is not checked.
$ ./togzoom
The target Zoom checkboxes were out of sync and are now not checked.
Run again to check the target Zoom checkboxes...
$ ./togzoom
The target Zoom checkboxes are now checked.
$ ./togzoom
The target Zoom checkboxes are now not checked.
$
Note: The example AppleScript code used herein is just that and does not contain any additional 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.
1 While the defaults
command can be used to modify .plist
files nonetheless, in this particular case com.apple.symbolichotkeys.plist
can be difficult and getting the changes in this and aforementioned files requires programmatically killing the users cfprefsd
daemon in an attempt to have the changes take effect. In some cases this process will fail and why scripting with AppleScript was chosen.