Non-graphical way to change mouse settings on MacOS circa Sonoma

  Kiến thức lập trình

I have to regularly change my mouse settings on my MBP when switching between walking on a treadmill and using my standing desk. I want to automate these changes to a script of some sort. Maybe something I can pull up with Raycast. I want to change mouse sensitivity and acceleration. I found that I can change the saved settings with:

   defaults write 'Apple Global Domain' com.apple.mouse.linear 0
   defaults write 'Apple Global Domain' com.apple.mouse.scaling 0.5

But, those do not affect the active values, only the saved preferences.

I tried playing around with AppleScript for the first time in my life only to find that it really doesn’t work to use scripts such as these:

-- Open System Preferences
tell application "System Settings" to activate

-- Attempt to change settings using System Events
tell application "System Events"
    tell process "System Settings"
        try
            -- Open the "Mouse" pane
            click menu item "Mouse" of menu "View" of menu bar 1
            delay 2
            -- set value of slider "Tracking speed" to 2
            -- delay 2
            -- click button "Advanced..."
            -- press button "Advanced..."
            set value of slider "Pointer acceleration" to off
        on error theError
            display dialog ("Sorry, an error occurred")
        end try
    end tell
end tell

It seems like support for AppleScript is a dying thing.

After searching for other approaches, I have come up short. Anyone have any suggestions?

LEAVE A COMMENT