ホーム 暮らし [Mac] Hammerspoon is great

[Mac] Hammerspoon is great

雨宮 千夏 雨宮 千夏 • 更新: • 公開: • 読了約 12 分
目次

Introduction

nca509e6bd686

Hello.
Is everyone doing it? Efficiency.
It has been a long time since DX and AI started to be shouted about for efficiency and automation.
When it comes to Mac efficiency, Alfred and Raycast are probably famous apps.
If you use these, app launching, file searching, and web searching seem to be lightning fast.

On the other hand, I use a tool called Hammerspoon.
It has been a favorite of mine for a long time because I can write my own scripts and customize it however I like.
Today, I will introduce Hammerspoon, my favorite software.

What is Hammerspoon?

Hammerspoon is a powerful automation tool for macOS.
As explained on the official website, its feature is that it is merely a "bridge between the Lua scripting engine and the OS."

In other words, it is not a tool of the type "
It's fun because it's packed with useful features from the start just by installing it!", but a tool of the type "
It's fun because I can write code myself to realize the features I want!
".

By the way, as mentioned earlier, it uses Lua as the language.

What can it do?

I will put aside the installation and configuration methods and introduce what can be achieved with Hammerspoon first.

Basically, I use it by "registering tasks that are troublesome to do with a mouse or trackpad to hotkeys and calling them."

Specifically,

  • Window operation system

    • Move & resize the active window to cover the right half of the screen

    • Move & resize the active window to cover the left half of the screen

    • Resize the active window to the maximum screen size

  • Application switching

    • Launch and activate a specific app with a specific hotkey.

      • ⌘ + G: Browser

      • ⌘ + Space: VS Code

      • ⌘ + T: Teams

    • So-called launcher-style usage

      • Select from all applications to launch and activate.

      • Select from currently running applications to launch and activate.

  • Todo management

    • ⌘ + ,: Show input field to add a Todo

    • ⌘ + /: Show incomplete Todos & complete by selecting

I have configured settings like these.

I suspect that many of these things can be done similarly using native Mac settings or other productivity tools.
In fact, other productivity tools might be better in terms of ease of use and the number of things they can do (out of the box).
Even so, the reason I use Hammerspoon is because

"the ultimate environment I've imagined"

it is fun to build.
If you are a fellow enthusiast who agrees, let's proceed to installation together.

Installation method

Official websiteFollow the steps written on the to install it.
It is super easy to do.

  1. https://github.com/Hammerspoon/hammerspoon/releases/tag/1.0.0 Download from here.

  2. Place Hammerspoon.app in /Applications.

That is all.
After that, launch Hammerspoon using your preferred method (double-click, from a launcher, etc.).
If you plan to use it extensively, I recommend setting it as an app that launches automatically when the OS starts.

Basic usage

Basically, you just write code in ~/.hammerspoon/init.lua.
Find the features that match what you want to do in the API documentation and implement them straightforwardly.

Getting Started with Hammerspoon I will quote what is written in below.

hs.hotkey.bind("cmd", "alt", "ctrl", "H", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()

  f.x = f.x - 10
  win:setFrame(f)
end)

I think you can understand the following even just by intuition.

  • When you press ⌘ + Alt + Ctrl + H simultaneously,

  • it moves in the negative direction by 10 units in the x direction

The related documentation is here.

  • docs » hs.hotkey

    • This is the API for operations such as creating new hotkeys.

  • docs » hs.window

    • This is the API for window operations.

Like this, you can achieve any behavior by using the APIs provided by Hammerspoon.
Since various APIs are provided, you can focus on implementing the logic of what you want to achieve without having to use difficult OS native APIs.

Note that when you update the configuration file, you need to press Reload Config from the Hammerspoon icon in the menu bar.

What?
You say it's a hassle to manually press reload every time?
Why don't you just automate it?
Because you already have Hammerspoon...
(The method is described in the aforementioned Getting Started with Hammerspoon. You monitor the path and use changes as a trigger.)

Conclusion

I wrote this sounding like an expert, but honestly, I don't think I've mastered even 10% of Hammerspoon's potential.
I've only set up a few hotkeys.
However, it is a fun and useful tool even just for that.
If you are interested, please give it a try.
Even if you are already using other efficiency tools, please try it.
You can never have too many useful tools, right?


同じカテゴリの記事

雨宮 千夏
デジタルマーケター 雨宮 千夏
プロフィールを見る →

アイドルと音楽シーンの取材を担当。公式サイトの公演情報、リリース告知、公開チャートを照合してから構成しています。

おすすめの関連記事