Skip to content

Instantly share code, notes, and snippets.

@luckman212
Last active January 31, 2022 05:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckman212/77493804de8e504490dfbc2835eef09c to your computer and use it in GitHub Desktop.
Save luckman212/77493804de8e504490dfbc2835eef09c to your computer and use it in GitHub Desktop.
quick popup note window for Hammerspoon
-- popper.lua
-- https://www.hammerspoon.org/docs/hs.webview.html
src=[[<html>
<head>
<style>
::-webkit-scrollbar {
background: #2d2e26;
width: 8px;
}
::-webkit-scrollbar-thumb {
background: #6f706c;
}
body {
background-color: #2d2e26;
}
textarea {
width: 100%;
height: 100%;
resize: none;
overflow-y: scroll;
background-color: transparent;
color: #f9f9f2;
border: none;
cursor: text;
padding: 8px;
font-family: 'SF Mono', SFMono-Regular, ui-monospace, monospace;
font-size: 1.7em;
line-height: 1.2em;
outline-color: transparent;
outline-style: none;
}
</style>
</head>
<body>
<textarea contentEditable="true" autofocus></textarea>
</body>
</html>]]
local init_w = 710
local init_h = 300
local screen = hs.mouse.getCurrentScreen()
local init_x = (screen:fullFrame().w/2) - (init_w/2)
local init_y = (screen:fullFrame().h/3) - (init_h/3)
wv = hs.webview.new(
hs.geometry.rect(init_x,init_y,init_w,init_h),
{
javaScriptEnabled=false,
javaScriptCanOpenWindowsAutomatically=false,
developerExtrasEnabled=false
}
)
-- wvw = wv:hswindow()
wv:allowMagnificationGestures(true)
wv:allowTextEntry(true)
wv:allowNewWindows(false)
wv:allowGestures(true)
wv:closeOnEscape(true)
wv:deleteOnClose(false)
wv:shadow(true)
wv:transparent(false) -- eliminate body bgcolor css
wv:windowStyle(31) -- hs.webview.windowMasks
wv:level(3) -- hs.drawing.windowLevels
-- hs.drawing.windowBehaviors
-- https://developer.apple.com/documentation/appkit/nswindow/collectionbehavior
wv:behaviorAsLabels({
'ignoresCycle',
'moveToActiveSpace'
})
wv:html(src)
function popper_toggle(bool)
if not wv then return end
if bool == false or wv:isVisible() then
wv:hide()
else
local mp = hs.mouse.absolutePosition()
wv:show():bringToFront(false)
c = hs.timer.doAfter(0.1, function()
local f = wv:frame()
hs.eventtap.leftClick({x=(f.x+(f.w/2)),y=(f.y+8)},100000)
hs.mouse.absolutePosition(mp)
end
)
-- wvw:focus()
end
end
local hk_popper = hs.hotkey.bind(nil, "f2", popper_toggle, nil, nil)
-- popper_toggle(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment