0%

How I Use Hammerspoon

Part one, to be continued.

According to the wording on its official website, Hammerspoon is:

a tool for powerful automation of OS X.

I use it with Amethyst to manage the windows, and apart from that, here is how I use it:

  • text editing with markdown;
  • work/rest timer;
  • double confirm when pressing ⌘ + Q;
  • one hotkey to toggle day&night mode;

pomo & slowq

Credits go to @dbmrq, dotfiles/home/.hammerspoon at master · dbmrq/dotfiles · GitHub

I use two of his plugins (let’s just call it that).

For slowq, it prevents you from quit your app when you accidentally press ⌘+Q, instead you need to hold for 2/3s to quit.

To use it, download the file, put it in your ~/.hammerspoon/ folder, then you just need to put one line of code in your init.lua:

1
require “slowq”

For work timer, you just need to add 3 lines of code:

1
2
3
4
require "pomo"

hs.hotkey.bind(hyper, '9', '🍅.enabled.🍅', function() pom_enable() end)
hs.hotkey.bind(hyper, '0', '🍅.disabled.🍅', function() pom_disable() end)

Then just press the hotkey and you will get a progress bar at the top of your screen, i just did a little tweek around, change the work/rest to emojis 🍅/☕️.

Hotkey to toggle night mode

First, I googled and write a little function in lua to read applescript files.

1
2
3
4
5
6
7
8
-- function: read applescript content. copy content to data
function applescript_reader(string)
local path = string
local file = io.open(path, "r")
local data = file:read("*a")
file:close()
return data
end

Then I assign a hotkey to call the applescript, long way…

1
2
3
4
5
6
7
8
hotkey.bind(
"alt",
"D",
function()
applescript(applescript_reader("/Users/daLi.h/.hammerspoon/your.applescript"))
alert.show("🌚...Dark or Light...🌝")
end
)

The content of the applescript file is simple:

1
2
3
4
5
6
7
8
9
tell application "System Events"
tell appearance preferences
if dark mode is false then
set dark mode to true
else
set dark mode to false
end if
end tell
end tell%

For window management and text editing part, let’s talk about it next time.

  • Post author: Dali Khan
  • Post link: https://yiti.ml/aa091/
  • Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.

Welcome to my other publishing channels