Skip to content

Instantly share code, notes, and snippets.

@emjayoh
Created May 8, 2020 01:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emjayoh/ad01f6483256a98a5f6fb3bc7a6da14f to your computer and use it in GitHub Desktop.
Save emjayoh/ad01f6483256a98a5f6fb3bc7a6da14f to your computer and use it in GitHub Desktop.
Hammerspoon - kitty terminal + dropdown visor (Guake)
hs.hotkey.bind({}, "F15", function()
local app = hs.application.get("kitty")
if app then
if not app:mainWindow() then
app:selectMenuItem({"kitty", "New OS window"})
elseif app:isFrontmost() then
app:hide()
else
app:activate()
end
else
hs.application.launchOrFocus("kitty")
app = hs.application.get("kitty")
end
app:mainWindow():moveToUnit'[100,50,0,0]'
app:mainWindow().setShadows(false)
end)
@csonuryilmaz
Copy link

Hi,

"setShadows()" gives error

hs.hotkey callback: /Users/onur/.hammerspoon/init.lua:18: method 'setShadows' is not callable (a nil value)
stack traceback:
	/Users/onur/.hammerspoon/init.lua:18: in function </Users/onur/.hammerspoon/init.lua:1>

on MacOS Big Sur 11.2.3 & Hammerspoon 0.9.90 (6030).

Also, "Enable Accessibility" should be enabled from Hammerspoon > Preferences. (for once if not enabled, or installed recently) Otherwise script is not working as expected. 😉

@vladdoster
Copy link

Yes, it is expected to enable accessibility, or else hammerspoon does not have permissions to specific APIs.

As for setShadows, it is stated that it is fragile.

This function uses a private, undocumented OS X API call, so it is not guaranteed to work in any future OS X release

http://man.hubwiz.com/docset/Hammerspoon.docset/Contents/Resources/Documents/hs.window.html#setShadows

@svenjacobs
Copy link

Line 6 doesn't work anymore with Kitty 0.26.4. It now should be

app:selectMenuItem({"Shell", "New OS Window"})

@svenjacobs
Copy link

Also I noticed that the positioning of the window doesn't work reliably on first start of Kitty. Here's my modified version of the script.

local app = hs.application.get("kitty")
local didHide = false

if app then
    if not app:mainWindow() then
        app:selectMenuItem({"Shell", "New OS Window"})
    elseif app:isFrontmost() then
        app:hide()
        didHide = true
    else
        app:activate()
    end
else
    hs.application.launchOrFocus("kitty")
    app = hs.application.get("kitty")
end

if not didHide then
  hs.timer.waitUntil(
    function() return app:isFrontmost() end,
    function() app:mainWindow():moveToUnit('[0,0,100,50]', 0) end
  )
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment