A Go library for interacting with AeroSpace WM via IPC
Minimum AeroSpace version: v0.15.x
This package allows interacting with AeroSpace WM via IPC.
It uses the available Unix Socket to communicate. The socket is typically located at /tmp/\(aeroSpaceAppId)-\(unixUserName).sock
(see).
As of now, this library only covers the functionality necessary for implementing aerospace-marks and aerospace-scratchpad which is:
- Windows
- Get all windows
- Get focused window
- Get window by ID
- Get windows by workspace
- Move window to workspace
- Set window layout
- Workspaces
- Get focused workspace
- Move workspace to another workspace
For the remaining functionality, this library exposes a SocketClient interface, which allows you to send raw commands and receive responses in pure JSON format.
See documentation for the full list of available methods.
If you need a specific functionality that is not yet implemented, feel free to open an issue or a pull request.
If you are creating an extension that relies a lot on querying the AeroSpace WM. Because it uses IPC (Inter-Process Communication) to communicate directly with the AeroSpace Unix socket, just like the built-in AeroSpace CLI. It allows you to avoid repeated process spawning. This approach offers lower latency and better efficiency.
To use this library in your Go project, add it as a dependency:
go get -u github.com/cristianoliveira/aerospace-ipc
To use the library, import it into your Go project and create a new AeroSpace connection:
import (
"errors"
"fmt"
"log"
aerospacecli "github.com/cristianoliveira/aerospace-ipc"
)
func main() {
client, err := aerospacecli.NewAeroSpaceConnection()
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer client.CloseConnection()
// This isn't strictly necessary, but it's a good practice to check the server version
err = client.Connection().CheckServerVersion()
if err != nil {
if error.Is(err, aerospacecli.ErrVersionMismatch) {
fmt.Printf("[WARN] %s\n", err)
} else {
log.Fatalf("Failed to connect: %v", err)
}
}
windows, err := client.GetAllWindows()
if err != nil {
log.Fatalf("Failed to get windows: %v", err)
}
for _, window := range windows {
fmt.Println(window)
}
}
See also in examples for more detailed usage examples.
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.