There are two accessibility settings (indicated by the red rectangle in the screenshot below) that allow for zooming into the screen by holding ctrl and scrolling the mouse.
Is there a way to enable those settings from the terminal?
accessibilitysettingsterminalzoom
Best Answer
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:
Copy and paste the example AppleScript code, shown further below, into the opened
togzoom
file.Save and close the file.
Make the file executable:
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 yourPATH
statement. Then it can be used from anywhere by justtogzoom
, (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:
To use the example AppleScript code in macOS Mojave, make the following change to the code shown above:
Change:
To:
What this script does:
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.
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 casecom.apple.symbolichotkeys.plist
can be difficult and getting the changes in this and aforementioned files requires programmatically killing the userscfprefsd
daemon in an attempt to have the changes take effect. In some cases this process will fail and why scripting with AppleScript was chosen.