Integrate Aersoapce tiling manager in sketchybar #599
-
Hello, I've started using a new performant tiling manager called Aerospace, and I'm replacing Amethyst with it. However, I haven't been able to fully integrate it into SketchyBar. I'm using Lua and was able to display the workspaces, but I haven't been able to get them to update. If anyone has Aerospace configured and could share their config, it would be greatly appreciated. thank you here is my config: local colors = require("colors")
local settings = require("settings")
local app_icons = require("icons")
local function lines(str)
local result = {}
for line in str:gmatch("[^\n]+") do
table.insert(result, line)
end
return result
end
local function icons_for_apps(app_names)
local icon_line = {}
for _, app in pairs(app_names) do
local lookup = app_icons[app]
local icon = ((lookup == nil) and app_icons["Default"] or lookup):gsub("iterm", "terminal")
table.insert(icon_line, icon)
end
return icon_line
end
sbar.exec("aerospace list-windows --all --format '%{workspace} %{app-name}'", function(all_workspaces)
local aerospaces = lines(all_workspaces)
local spaces = {}
for i, sid in pairs(aerospaces) do
local space_name = "space." .. sid
local space = sbar.add("item", space_name, {
icon = {
font = { family = settings.font.numbers },
string = sid,
padding_left = 15,
padding_right = 8,
color = colors.white,
highlight_color = colors.red,
},
label = {
padding_right = 20,
color = colors.grey,
highlight_color = colors.white,
font = "sketchybar-app-font:Regular:16.0",
y_offset = -1,
},
padding_right = 1,
padding_left = 1,
background = {
color = colors.bg1,
border_width = 1,
height = 26,
border_color = colors.black,
},
popup = { background = { border_width = 5, border_color = colors.black } },
})
if sid ~= nil then
spaces[sid] = space
end
space:subscribe("aerospace_workspace_change", function(env)
selected = env.FOCUSED_WORKSPACE == sid
space:set({ background = { drawing = selected } })
end)
space:subscribe("space_windows_change", function(env)
-- run window change events only on first item, since aerospace places everyting on a single space and this events get's triggered for every item
local is_first = env.NAME == "space.1"
if is_first == true then
icons_for_apps(spaces)
end
end)
end
icons_for_apps(spaces)
end)
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Here is a minimal snippet that shows all aerospace workspaces in lua: local colors = require("colors")
function parse_string_to_table(s)
local result = {}
for line in s:gmatch("([^\n]+)") do
table.insert(result, line)
end
return result
end
local file = io.popen("aerospace list-workspaces --all")
local result = file:read("*a")
file:close()
local workspaces = parse_string_to_table(result)
for i, workspace in ipairs(workspaces) do
local space = sbar.add("item", "space." .. i, {
icon = {
string = workspace,
color = colors.white,
highlight_color = colors.red,
},
label = { drawing = false },
padding_left = 1,
padding_right = 1,
})
space:subscribe("aerospace_workspace_change", function(env)
local selected = env.FOCUSED_WORKSPACE == workspace
space:set({
icon = { highlight = selected, },
label = { highlight = selected },
background = { border_color = selected and colors.white or colors.bg2 }
})
end)
end Using shell scripts is also possible and nicely detailed here: https://nikitabobko.github.io/AeroSpace/goodness#show-aerospace-workspaces-in-sketchybar Dont forget to add the event to aerospace.toml: # Notify Sketchybar about workspace change
exec-on-workspace-change = ['/bin/bash', '-c',
'sketchybar --trigger aerospace_workspace_change FOCUSED_WORKSPACE=$AEROSPACE_FOCUSED_WORKSPACE'
] Displaying the current window application icons for each aerospace workspace is not robustly possible, because some events for that are missing, see: nikitabobko/AeroSpace#316 |
Beta Was this translation helpful? Give feedback.
Here is a minimal snippet that shows all aerospace workspaces in lua: