Yabai.spoon
NOTE:
no longer using it or intending to maintain it see #2.
Yabai.spoon is lua 5.4 library to interact with yabai socket directly within lua. It's written in rust using mlua awesome library and yes it's extremely fast and efficient.
Features
- Support almost all yabai commands through table access.
- Efficient and lightweight.
- EmmyLua annotations (IDE completion should support discoverability).
- Auto serialization of Yabai types to Lua tables.
Usage example
There are many commands, here a simple example to show case usage.
local yabai = require'yabai' -- or depending on how you've installed require'Spoons.Yabai.spoon'
-- Query ------------------------------------------
yabai.query.spaces.all --> return all spaces
yabai.query.spaces.current --> return current spaces
yabai.query.spaces[1] --> return space at index 1
yabai.query.displays.all --> return all displays
yabai.query.displays.current --> return current display
yabai.query.displays[1] --> return display at index 1
yabai.query.windows.all --> return all windows
yabai.query.windows.current --> return current window
yabai.query.windows[1] --> error out
-- print all open applications
for _, space in ipairs(yabai.query.window.all()) do
print(window.app)
end
-- Window ------------------------------------------
-- Returns false on failure
yabai.window.focus.next() -- focus on next window
yabai.window.focus.prev() -- focus on prev window
yabai.window.focus.stack.next() -- select next window in the stack
yabai.window.toggle.float() -- make current window floating
yabai.window.toggle.close() -- close current window
yabai.window.space[3]() -- move window to space with id 3.
yabai.window.space.next() -- move window to next space.
-- Space ------------------------------------------
yabai.space.focus.main() -- focus on space with label main.
yabai.space.focus[1]() -- focus on space with id 1
yabai.space.move.next() -- move current space to next space
yabai.space.move.next() -- move current space to next space
--- ......
Installation
There are few ways to install [Yabai.spoon], pick what makes more sense to you.
Nix
If you are using flakes and home:
inputs.yabaispoon.url = "github:tami5/Yabai.spoon/master";
# .....
home.file".hammerspoon/yabai" =
"${inputs.yabaispoon.packages.yabaispoon}/share/lua/5.4/Yabai.spoon/init.lua";
home.file".hammerspoon/yabai" =
"${inputs.yabaispoon.packages.yabaispoon}/share/lua/5.4/Yabai.spoon/libyabai.lua";
Release
Soon
Cargo
Clone the repo, then cargo build --release
. Afterwords:
cp $root_dir/target/release/libyabai.dylib ~/.hammerspoon/libyabai.dylib
cp $root_dir/init.lua ~/.hammerspoon/yabai.lua # or Spoons/Yabai.spoon/init.lua
# OR to keep your dotfiles clean
cp $root_dir/target/release/libyabai.dylib /Applications/Hammerspoon.app/Contents/Frameworks/
cp $root_dir/init.lua /Applications/Hammerspoon.app/Contents/Resources/extensions/yabai.lua