Created
March 25, 2024 10:27
-
-
Save honmaple/84205e7992879ac3ff019d602250e57d to your computer and use it in GitHub Desktop.
Like i3wm's scratchpad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local _M = { | |
scratchpad = {} | |
} | |
local yabai = string.gsub(hs.execute("which yabai", true), "%s+", "") | |
_M.init = function() | |
local output, status = _M.exec("query --windows") | |
if not status then return end | |
local windows = hs.json.decode(output) | |
for _, window in pairs(windows) do | |
if window["is-hidden"] then | |
table.insert(_M.scratchpad, window) | |
end | |
end | |
end | |
_M.exec = function(args) | |
local command = string.format("%s -m %s", yabai, args) | |
print(command) | |
return hs.execute(command) | |
end | |
_M.show_scratchpad = function(name) | |
for index, window in pairs(_M.scratchpad) do | |
if not name or name == window["app"] then | |
table.remove(_M.scratchpad, index) | |
local app = hs.application.find(window["pid"]) | |
app:unhide() | |
app:activate(true) | |
-- 先移动,再切换浮动 | |
-- _M.exec(string.format("window %d --move abs:%d:%d", window["id"], window["frame"]["x"], window["frame"]["y"])) | |
if not window["is-floating"] then | |
_M.exec(string.format("window %d --toggle float", window["id"])) | |
end | |
return | |
end | |
end | |
if name then | |
hs.notify.new({informativeText="应用未找到"}):send() | |
return | |
end | |
local output, status = _M.exec("query --windows --window") | |
if not status then return end | |
local window = hs.json.decode(output) | |
if window and window["is-floating"] then | |
table.insert(_M.scratchpad, window) | |
local app = hs.application.find(window["pid"]) | |
return app:hide() | |
-- return _M.exec("window --move abs:10000:10000") | |
end | |
hs.notify.new({informativeText="没有隐藏应用"}):send() | |
end | |
_M.move_to_scratchpad = function() | |
local output, status = _M.exec("query --windows --window") | |
if not status then return end | |
local window = hs.json.decode(output) | |
if window and window["has-focus"] then | |
table.insert(_M.scratchpad, window) | |
if not window["is-floating"] then | |
_M.exec("window --toggle float") | |
end | |
local app = hs.application.find(window["pid"]) | |
return app:hide() | |
-- return _M.exec("window --move abs:10000:10000") | |
end | |
hs.notify.new({informativeText="应用未找到"}):send() | |
end | |
return _M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment