News for hackers. Stuff that matters.
Re:Ask HN: How to make my macOS less distracting? by seanhunter on Sunday January 23, 2022 @02:34AM (#30044345)
I use hammerspoon (https://www.hammerspoon.org/) and have a section in my ~/.hammerspoon/init.lua that puts things into "focus mode" where it centers my current focussed window and minimizes everything else. If I used notifications (I turn them all off all the time) I would put it into do not disurb mode during this time also. Here's a snippet that does this:

    focusTimer = nil        -- A timer for when we are in "Focus Mode"
    function focusModeOff()
        all = hs.window.allWindows()
        for _, w in pairs(all) do
            if(w:isMinimized()) then
                w:unminimize()
            end
        end
        applyStandardLayout()
        if(focusTimer ~= nil) then
            focusTimer:stop()
            focusTimer = nil
        end
    end

    -- Focus mode
    function focusMode()
        if(focusTimer == nil) then
            hs.alert("Setting focus for 25mins.")
            local focused = hs.window.focusedWindow()
            if(focused ~= nil) then
                focused:centerOnScreen()
            end
            all = hs.window.allWindows()
            for _, w in pairs(all) do
                if(focused ~= nil and w:id() ~= focused:id()) then
                    w:minimize()
                end
            end
            focusTimer = hs.timer.doAfter(25 * 60, function()
                focusModeOff()
                hs.alert("Take a 5min break. Record what you just did.")
                --TODO: Make a pomodoro recording thing
            end)
        else
            local remaining = focusTimer:nextTrigger()
            local remainingSec = math.floor(remaining % 60)
            local remainingMin = math.floor(remaining / 60)
            hs.alert("Focus timer expires in " .. remainingMin .. "m " .. remainingSec .. "s.")
        end
    end

    --focus mode
    hs.hotkey.bind({"cmd", "ctrl"}, "Return", focusMode)

There are no comments on this comment yet.