Skip to content

Dropdown terminal

28th January 2023

I wanted a dropdown terminal anywhere (Guake style), and so found a few resources online. After some searching, this Github issue and gist solved my problem. Generally, you shouldn't be executing random bits of code on the internet on your personal machine, so I read through to make sure it wasn't doing anything malicious, and along the way made some simplifications.

How to:

  1. Install Hammerspoon.
  2. Add an ~/.hammerspoon/init.lua file with the code here.
  3. (Optional) If you're not using Alacritty (terminal emulator) then change accordingly. You can also change the hotkey.
  4. Launch Hammerspoon and press + \ to show and hide the terminal! Even works across macOS desktop spaces.
lua
-- file: ~/hammerspoon/init.lua

local screen = require 'hs.screen'
local hotkey = require 'hs.hotkey'
local application = require 'hs.application'

local APP = 'Alacritty'

-- Toggle app
hotkey.bind({'cmd'}, '\\', function () -- cmd + backslash
  local app = application.get(APP)
  if app ~= nil and app:isFrontmost() then
    app:hide()
  -- ensure Alacritty is launched
  elseif app ~= nil then
    win = app:mainWindow()
    win:focus()
  end
end
)