Change mouse speed in terminal without restarting

I couldn't find a way to do it with terminal alone so I had to create an Apple Script.

I found a script here: https://stackoverflow.com/questions/1680775/setting-the-mouse-tracking-speed-via-applescript

However, this did not work for me in Mojave so I had change it a littler. I also changed it so that it accepts a parameter which it will then forward to the tracking speed slider.

on run (trackingValue)
--Open and activate System Preferences
tell application "System Preferences" to activate

--Attempt to change settings using System Events
tell application "System Events"
    tell process "System Preferences"
        try
            delay 1
            --Open the "Mouse" pane
            click menu item "Mouse" of menu "View" of menu bar 1
            delay 0.5
            tell window "Mouse"
                tell slider "Tracking speed" of tab group 1
                    set value to round of trackingValue rounding down
                end tell
            end tell
        on error theError
            --An error occured
            display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
        end try
    end tell
end tell

tell application "System Preferences" to quit
end run

You can then run this via terminal by calling:

osascript /<SCRIPT_LOCATION>/<NAME_OF_SCRIPT>.scpt <TRACKING_SPEED_VALUE>

You will need to give your Terminal accessibility access for this to work.