How to increase cursor size programmatically?

Unfortunately the command line command defaults, which can read and or write the value of the mouseDriverCursorSizekey in thecom.apple.universalaccess .plist file, the write command, e.g. defaults write com.apple.universalaccess mouseDriverCursorSize 2.5 doesn't take immediate affect and may actually get overwritten before the change can take effect. Note: The mouseDriverCursorSize key in com.apple.universalaccess .plist file does not exist unless the default value has previously been changed.

While you said you didn't want to go the GUI route with e.g. AppleScript, how about you split the difference and do it from the command line using osascript to process the AppleScript code, which does make the change from System Preferences, but without being interrupted by the System Preferences UI. As a matter of fact, assuming the System Preferences Dock Tile is still present, as is its default, all you'll see is the System Preferences Dock Tile bounce once, and no System Preferences UI. (This assumes it wasn't open to begin with.)

If that's acceptable, then the following AppleScript code saved as a command line executable will do the job:

  • Note: The value shown for theCursorSize is what my system is presently set to.
#!/usr/bin/osascript

    -- # set theCursorSize between 1.0 and 4 (Valid intermediate values may run out 12 decimal places.)

set theCursorSize to 1.388884782791

    -- # Get the system minor version number, as an integer.

set theSystemVersion to system version of (system info)
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set theMinorSystemVersion to text item 2 of theSystemVersion as integer
set AppleScript's text item delimiters to TID

    -- # Change the size of the mouse cursor.

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
    delay 0.5   -- # Modify as/if necessary. Value is in seconds as a decimal number.
    tell application "System Events"
        if theMinorSystemVersion is equal to 8 then
            set value of value indicator 1 of slider 2 of group 1 of window "Accessibility" of application process "System Preferences" to theCursorSize
        else if theMinorSystemVersion is equal to 9 then
            set value of value indicator 1 of slider 2 of window "Accessibility" of application process "System Preferences" to theCursorSize
        else if theMinorSystemVersion is greater than 9 and theMinorSystemVersion is less than 13 then
            set value of value indicator 1 of slider 1 of window "Accessibility" of application process "System Preferences" to theCursorSize
        end if
    end tell
    quit
end tell

Note: As coded, this script works with OS X 10.8 through macOS 10.12. I have not tested this under macOS High Sierra, however if nothing has changed between macOS 10.12 and macOS 10.13 with this particular object, then the less than 13 then code segment can be changed to less than 14 then, or if you prefer, shorten the line of code to just:

else if theMinorSystemVersion is greater than 9 then

To create a command line executable, containing the above AppleScript code, do the following in Terminal:

touch cmcs
open cmcs
  • Copy and paste the above AppleScript code into the opened cmcs document.
  • Set the value of theCursorSize to your preferred cursor size.
  • Save the document, pressing: ⌘S

Back in Terminal, make cmcs executable:

chmod u+x cmcs

Now the cmcs command line executable can be executed by typing: ./cmcs

  • Note: If you place the cmcs command line executable in a location defined within the PATH environment variable, you can omit the leading ./, and or having to type /path/to/cmcs. Also note that the naming of, cmcs is for change mouse cursor size, and can be whatever you want it to be otherwise.

Additional Notes:

The value of mouseDriverCursorSize key in the com.apple.universalaccess .plist file is stored rounded to the 6th decimal place, e.g, 1.388884782791 is saved as 1.388885

To get the full value, in Script Editor, run the following script:

set theSystemVersion to system version of (system info)
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set theMinorSystemVersion to text item 2 of theSystemVersion as integer
set AppleScript's text item delimiters to TID

tell application "System Preferences"
    reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
    delay 0.5 -- # Modify as/if necessary. Value is in seconds as a decimal number.
    tell application "System Events"
        if theMinorSystemVersion is equal to 8 then
            get value of value indicator 1 of slider 2 of group 1 of window "Accessibility" of application process "System Preferences"
        else if theMinorSystemVersion is equal to 9 then
            get value of value indicator 1 of slider 2 of window "Accessibility" of application process "System Preferences"
        else if theMinorSystemVersion is greater than 9 and theMinorSystemVersion is less than 13 then
            get value of value indicator 1 of slider 1 of window "Accessibility" of application process "System Preferences"
        end if
    end tell
    quit
end tell

Update to address comment:

If you're wanting to run this each time a User logs in, the I'd do the following:

In Automator create a new Application workflow and add a Run AppleScript action to it.

In the Run AppleScript action, replace (* Your script goes here *) and return input with all but the shebang (#!/usr/bin/osascript) of the first AppleScript code. The shebang isn't necessary since this is being run in an Run AppleScript action vs. a Run Shell Script action.

Save the Automator Application workflow as e.g. Set Mouse Cursor Size in the /Applications folder.

In System Preferences, do two things...

  • In Users & Groups > select target User > Login Items and add Set Mouse Cursor Size to the list of Login Items.

  • In Security & Privacy > Privacy > Accessibility, add Set Mouse Cursor Size to the Allow the apps below to control your computer list.

    • Note: the above is for OS X 10.9 and later. For OS X 10.8, Accessibility and check the Enable access for assistive devices check box.

Then each time the User logs in, the Set Mouse Cursor Size will run and do as programmed.


Here is the Javascript code for macOS Monterey:

function fn() {
    const cursorSizeSmall = 1 
    const cursorSizeLarge = 4
    
    const isRunningSystemPreferences = Application('System Preferences').running()
    Application('System Preferences').panes.byId('com.apple.preference.universalaccess').anchors.byName('Seeing_Cursor').reveal()
    const process = Application('System Events').processes.byName('System Preferences')
    while (process.windows.length == 0) {}
    const window = process.windows[0]
    while (window.groups.length == 0) {}
    const group = window.groups[0]
    while (group.tabGroups.length == 0) {}
    const tabGroup = group.tabGroups[0]
    while (tabGroup.sliders.length == 0) {}
    const slider = tabGroup.sliders[0]
    if (slider.value() == cursorSizeSmall) {
        slider.value = cursorSizeLarge
    } else {
        slider.value = cursorSizeSmall
    }
    if (!isRunningSystemPreferences) {
        Application('System Preferences').quit()
    }
}

fn()

You can use this snippet in the "Script Editor" app to create a new JXA script (make sure to set the language to JavaScript):

enter image description here

or use the Shortcuts app introduced in Monterey (link).