Hammerspoon plugin and API to interact with Yabai socket directly

Overview

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
You might also like...
Bevy plugin for the GGRS P2P rollback networking library.

Bevy_GGRS Bevy plugin for the ๐Ÿ‘‰ GGRS P2P rollback networking library. The plugin creates a custom stage with a separate schedule, which handles corre

Barebones egui_baseview vst2 plugin with basic parameter control
Barebones egui_baseview vst2 plugin with basic parameter control

egui_baseview_test_vst2 Based on baseview_test_vst2 Barebones baseview/egui_baseview vst2 plugin. It implements an egui ui for the vst gain effect exa

Barebones imgui_baseview vst2 plugin with basic parameter control
Barebones imgui_baseview vst2 plugin with basic parameter control

imgui_baseview_test_vst2 Based on baseview_test_vst2 Barebones baseview/imgui_baseview vst2 plugin. It implements a imgui-rs ui for the vst gain effec

A WireGuard UWP VPN plugin.

WireGuard UWP A Universal Windows Platform (UWP) VPN Plug-in for WireGuardยฎ written in Rust. Windows provides a plug-in based model for adding 3rd-par

A mini-CI as a Zellij plugin
A mini-CI as a Zellij plugin

About This Zellij plugin is a "mini-ci". It allows you to specify commands that will run in parallel, keeping track of completed commands and their ex

๐Ÿ”Œ A curseforge proxy server, keeping your API key safe and sound.

๐Ÿ”Œ CFPROXY - The curseforge proxy server Curseforge has locked down their API and now restricts access without authentification. This spells trouble f

A simple API gateway written in Rust, using the Hyper and Reqwest libraries.

API Gateway A simple API gateway written in Rust, using the Hyper and Reqwest libraries. This gateway can be used to forward requests to different bac

Docker daemon API in Rust

Bollard: an asynchronous rust client library for the docker API Bollard leverages the latest Hyper and Tokio improvements for an asynchronous API cont

A pure Rust implementation of WebRTC API
A pure Rust implementation of WebRTC API

A pure Rust implementation of WebRTC API

Releases(v0.4.0)
  • v0.4.0(Feb 17, 2022)

    Full Changelog: https://github.com/tami5/Yabai.spoon/compare/v0.3.0...v0.4.0

    Highlights

    • Add space and display commands.
    • Add ability to execute all function using space label.
    • Simplify initialization
    • Add emmylua types for space and display actions
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Feb 17, 2022)

    Full Changelog: https://github.com/tami5/Yabai.spoon/compare/v0.2.0...v0.3.0

    Highlights:

    • Make yabai socket path static [^1]
    • Add all yabai window actions, mimicking the cli version as much as possible: e.g.
      yabai.window.focus[2112]() -- focus window by id
      yabai.window.focus.next() -- focus window by one of window select commands.
      yabai.window.space[2122]() -- move window space with the given id
      yabai.window.space.next() -- move window to next space
      
    • Emmylua definitions for all window fields
    • Move query table creator to query.rs

    Footnotes: [^1]: This made the code more readable but required having unsafe keyword, this hopefully won't break anything (finger crossed ๐Ÿ˜†)

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Feb 16, 2022)

    Full Changelog: https://github.com/tami5/Yabai.spoon/compare/v0.1.0...v0.2.0

    Highlights:

    • Query Yabai: query.spaces[1], query.windows.all. [^1]
    • Get Lua tables (display, space and window).
    • Minor Changes to Yabai schema.[^2]
    • EmmyLua types to query field for completion and discoverability ๐ŸŽ‰
    • Only build for darwin since it's yabai only useable in darwin ๐Ÿ˜‰
    • Increase format width to 100 for better readability.

    Footnotes: [^1]: accessing query subfields will query yabai and return new table [^2]: mostly with can_

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Feb 16, 2022)

    Full Changelog: https://github.com/tami5/Yabai.spoon/commits/v0.1.0

    Highlights:

    • Setup of flake.nix
    • devshell: commands to help with debugging inspect, binspect, run, brun
    • devshell: setup lua environment, in addition to inspect.lua.
    • Error handling: if error happens anywhere, it should be a lua error.
    • Send messages to yabai socket and return output as string.
    Source code(tar.gz)
    Source code(zip)
Owner
Wandering, exploring, making mistakes and actively pushing limits along the way.
null
A rust client and structures to interact with the Clever-Cloud API.

Clever-Cloud Software Development Kit - Rust edition This crate provides structures and client to interact with the Clever-Cloud API. Status This crat

Clever Cloud 6 Jun 3, 2022
General-purpose asynchronous socket stream.

async-socket This crate implements a general-purpose asynchronous socket. The Socket implements AsyncRead, AsyncWrite, Stream and Clone traits and thu

Kristijan Sedlak 3 Oct 20, 2021
A minimalist socket-based client/server in Rust to illustrate a tutorial

The basics of unix sockets This repository serves as a reference for this tutorial blogpost How to run Install Rust and Cargo, and then do: cargo run

Emmanuel Bosquet 4 Dec 4, 2022
A rust implementation of websock/socket proxy. Support noVNC

websockify-rs: WebSockets support for any application/server This is a rust implement of the websockify-js, which is part of the noVNC project. At the

null 3 Jan 10, 2023
Socket.io client written in Rust

Rust-socketio-client An implementation of a socket.io client written in the rust programming language. This implementation currently supports revision

Hand of Midas 4 May 9, 2023
๐Ÿ˜ Query your Postgres Database directly from the Browser.

Postgres Browser Proxy Query your Postgres Database directly from the Browser. Video: https://youtu.be/ohr9gBPC3cE Download the latest binaries: https

Yannick 6 Jan 7, 2023
The Safe Network Core. API message definitions, routing and nodes, client core api.

safe_network The Safe Network Core. API message definitions, routing and nodes, client core api. License This Safe Network repository is licensed unde

MaidSafe 101 Dec 19, 2022
Modrinth API is a simple library for using Modrinth's API in Rust projects

Ferinth is a simple library for using the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 20 Dec 8, 2022
Proxy copilot api to openai's gpt-4 api

Proxying Copilot API to OpenAI's GPT-4 API Usage Start the Server export GHU_TOKEN=ghu_xxxx; ./copilot2chat Or sh start.sh start # start the server th

Smark 3 Dec 6, 2023
A Rust compiler plugin and support library to annotate overflow behavior

overflower This project contains a compiler plugin and supporting library to allow the programmer to annotate their code to declare how integer overfl

null 104 Nov 28, 2022