Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying the hs.mouse.trackingSpeed() setting #3744

Open
guillaume-azarias opened this issue Jan 29, 2025 · 3 comments
Open

Applying the hs.mouse.trackingSpeed() setting #3744

guillaume-azarias opened this issue Jan 29, 2025 · 3 comments

Comments

@guillaume-azarias
Copy link

Hi,

I want to set the mouse tracking speed according to my location. I added this script to my init.lua file loaded at start by Hammerspoon:

home_wifi = "home_wifi_name"
work_wifi = "work_wifi_name"

function updateMouseSpeed()
    local currentWiFi = hs.wifi.currentNetwork()
    
    if hs.fnutils.contains(home_wifi, currentWiFi) then
        hs.mouse.trackingSpeed(3.0)  -- Maximum speed
        hs.alert.show("Mouse tracking speed set for home location")
    elseif currentWiFi == work_wifi then
        hs.mouse.trackingSpeed(0.0)  -- Minimum speed
        hs.alert.show("Mouse tracking speed set for work location")
    else
        hs.mouse.trackingSpeed(1.5)  -- Default speed
        hs.alert.show("Default mouse speed")
    end
end

-- Run the script at start
local tracking_speed = hs.mouse.trackingSpeed()
hs.alert.show(tracking_speed)
updateMouseSpeed()
local tracking_speed = hs.mouse.trackingSpeed()
hs.alert.show(tracking_speed)

The value shown of hs.mouse.trackingSpeed() is changed by the location, but it does not affect the real value set in the system preferences. Is there a way to apply the setting ?
Thank you for your support,
Guillaume

MacBook Pro, M1 Pro, 2021, macOS Sequoia 15.2

@asmagill
Copy link
Member

FWIW, when I use hs.mouse.trackingSpeed (and I have an external USB mouse attached), it updates the Mouse Tracking Speed, not the Trackpad Tracking Speed...

Are you using an external mouse or the trackpad? If the trackpad, I'm not sure that the current code can do that -- it doesn't seem to on my M2 MacBook Pro running Sonoma 14.7.1 (suppose I need to upgrade at some point)... I can try and dig a little, but it will probably be this weekend or next week before I can.

@asmagill
Copy link
Member

I should add, even with the mouse not attached, the trackpad setting doesn't change, so... assuming it's a limitation of the current code until I can look closer at how it's doing the work...

@asmagill
Copy link
Member

asmagill commented Feb 1, 2025

Ok, I have identified that the trackpad uses a different property name (HIDTrackpadAcceleration instead of HIDMouseAcceleration), and have added code to allow getting and setting it, similar to the existing mouse code; however, while it does change the value shown in the System Settings, it does not seem to actually change the active tracking speed; I suspect a logout/login might apply the new value, since it does seem to be adjusting whatever it is System Settings queries, but a way to do so at the time of the change should also be possible... I'm going to have to dig more and play with it a bit before uploading a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants