Daily Shaarli

All links of one day in a single page.

November 15, 2019

Hammerspoon Getting Started

Le Getting Started pour utiliser Hammerspoon sur MacOS

What is Hammerspoon?

Hammerspoon is a desktop automation tool for OS X. It bridges various system level APIs into a Lua scripting engine, allowing you to have powerful effects on your system by writing Lua scripts.

C'est super puissant pour controller MacOS.

Quelques examples:

  • Déplacer la fenêtre actuelle sur la moitié gauche de l'écran en pressant les touches Cmd, alt, ctrl et gauche
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Left", function()
    local win = hs.window.focusedWindow()
    local f = win:frame()
    local screen = win:screen()
    local max = screen:frame()

    f.x = max.x
    f.y = max.y
    f.w = max.w / 2
    f.h = max.h
    win:setFrame(f)
end)
  • Déplacer la fenêtre actuelle sur la moitié droite de l'écran en pressant les touches Cmd, alt, ctrl et droite
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Right", function()
    local win = hs.window.focusedWindow()
    local f = win:frame()
    local screen = win:screen()
    local max = screen:frame()

    f.x = max.x + (max.w / 2)
    f.y = max.y
    f.w = max.w / 2
    f.h = max.h
    win:setFrame(f)
end)
  • Afficher le titre en écoute sur Spotify en pressant les touches Cmd, alt, ctrl et S
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "S", function()
    hs.spotify.displayCurrentTrack()
end)