Skip to content

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

@guillaume-azarias

Description

@guillaume-azarias

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions