Hammerspoon

(github.com)

48 points | by tosh an hour ago ago

19 comments

  • zdw 5 minutes ago ago

    I fake a tiling window manager on Mac with Hammerspoon, resizing to fit in specific corners/sizes:

         -- resize based on ratios
        function ratioResize(xr, yr, wr, hr)
          return function ()
            local win = hs.window.focusedWindow()
            win:moveToUnit({x=xr,y=yr,w=wr,h=hr})
          end
        end
    
        -- 4 corners, different sizes
        hs.hotkey.bind({"cmd", "ctrl"}, "w", ratioResize(0,     0, 2/5, 2/3))
        hs.hotkey.bind({"cmd", "ctrl"}, "e", ratioResize(2/5,   0, 3/5, 2/3))
        hs.hotkey.bind({"cmd", "ctrl"}, "s", ratioResize(0,   2/3, 2/5, 1/3))
        hs.hotkey.bind({"cmd", "ctrl"}, "d", ratioResize(2/5, 2/3, 3/5, 1/3))
    
    And to throw windows to other monitors:

        -- send to next screen
        hs.hotkey.bind({"cmd", "ctrl"}, ";", function()
          local win = hs.window.focusedWindow()
          local screen = win:screen()
          local next_screen = screen:next()
    
          win:moveToScreen(next_screen)
        end)
  • jmcguckin 4 minutes ago ago

    I use it to give me focus-follows-mouse and to have a large circle surrounding the mouse when i move it, to aid finding it.

  • incanus77 27 minutes ago ago

    Hammerspoon is the glue that holds my Mac together. For a starter list of things to do with this app, a partial list of the things that I'm using it for:

      - Dumping all open Safari tabs to an Obsidian doc
      - Adding 'hyper' (Ctrl-Opt-Cmd) keybinds to pop a new window for:
        - Safari
        - Finder
        - Terminal (Ghostty)
        - VS Code
        - Notes
        - Editing Hammerspoon/AeroSpace/Sketchybar config
        - Reloading Hammerspoon config
        - Reloading Sketchybar
        - Quitting all Dock apps except Finder
        - Screen lock
        - System sleep
        - Opening front Finder folder in VS Code
        - Opening front Safari URL on Archive.today
        - Showing front Safari window tab count
        - Showing front app bundle ID
        - Posting notification about current Music track
        - Controlling my Logi Litra light (various color temps/brightnesses)
        - Starting/stopping a client work timer
      - Tying it to AeroSpace for:
        - Pushing a window to another monitor
        - Performing a two-up window layout
        - Swapping those two windows
        - Closing all other workspace windows
        - Gathering all windows to first workspace
      - Ensuring some background apps stay running if they crash
      - Prompting to unmount disk images if trashed
      - Binding into Skim to jump to specific sections of spec PDFs using terse Markdown URLs
  • pjm331 an hour ago ago

    here is my entire config

        hs.hotkey.bind({"ctrl"}, "D", function()
          hs.grid.show()
        end)
    
    i've tried all of the other fancy window managers and for me nothing has ever beat the ease of use of just

    (1) ctrl-d to see the grid, (2) type the letter where you want the top left corner of your window to be, (3) type the letter where you want the bottom right corner to be

    window resized

    • elAhmo 18 minutes ago ago

      This is amazing! I have a slightly more elaborate setup that allows me to resize from one or another side, similar to what Apple added recently but with more flexibility, but this is super interesting, thanks for sharing!

    • stackghost 35 minutes ago ago

      Not that I insert EOFs very often, but does that conflict with CTRL+D in the terminal?

      • pjm331 6 minutes ago ago

        yeah the CTRL+D definitely gives me problems from time to time but thus far i have been too lazy to fix it

      • xyzzy_plugh 33 minutes ago ago

        I use EOF all the time to end terminal sessions.

  • weitzj 12 minutes ago ago

    I love hammerspoon. That's it :D

    It's lua, so you can get creative with https://fennel-lang.org/

  • mwagstaff 16 minutes ago ago

    Can't live without Hammerspoon on Mac.

    Can't live without AutoHotkey on Windows.

    Thanks to everyone who contributed to both!

  • hmokiguess 6 minutes ago ago

    what's your favourite spoon?

  • jjmiv an hour ago ago

    is there a particular reason this was shared?

    otherwise I'm slowly working on a Spoon that figures out if there is an active meeting in Zoom, Teams, Huddle, Google Meet and will allow for muting, video enable/disable and screen sharing etc

  • golem14 an hour ago ago

    Has anyone worked on making a config replicating aerospace?

    Hammerspoon seems like a superset and it’s probably better to just have one, instead of two tools warring about who gets the keypresses?

    • hirvi74 8 minutes ago ago

      What features are you trying to replicate from Aerospace?

  • trjordan 33 minutes ago ago

    I utterly love Hammerspoon.

    It's fun to combine with qmk [0], which gives you a bunch more options for hotkeys on your keyboard via layers. I've ended up with a layer where half the keyboard is Hammerspoon shortcuts directly to apps (e.g. go to Slack, to Chrome, etc.) and half of it is in-app shortcuts (like putting cmd-number on the home row, for directly addressing chrome tabs).

    Between this and one of the tiling window manager-adjacent tools (I use Sizeup), I can do all my OS-level navigation directly. "Oh I want to go to Slack and go to this DM" is a few keystrokes away, and not dependent on what else I was doing.

    [0] https://qmk.fm/

  • hirvi74 14 minutes ago ago

    I have fond memories of this app. However, after many years, I have moved on. I am in the process of writing my own replacement for some of the various use cases that Hammerspoon once provided me. Though, Hammerspoon will always be a source of great inspiration.

  • john-tells-all an hour ago ago

    I'd love to have a global "toggle Teams mute" button.

    • hirvi74 6 minutes ago ago

      What do you mean? Like muting the entire application so no sound comes from Teams or muting yourself while on a call? For the latter, I thought 'Option + Space' worked (or used to)?

  • rolymath 40 minutes ago ago

    Is paperwm jittery for everyone?