SbarLua
SbarLua copied to clipboard
Volume Control Gets Stuck at Specific Values (67% or 00%)
The volume control in the sketchybar widget occasionally gets stuck at specific values, particularly at 67% or 00%.
local colors = require("colors")
local icons = require("icons")
local settings = require("settings")
local volume_slider = sbar.add("slider", 100, {
drawing = false,
position = "right",
updates = true,
label = { drawing = false },
icon = { drawing = false },
slider = {
highlight_color = colors.accent,
width = 0,
background = {
height = 6,
corner_radius = 3,
color = colors.grey,
padding_left = 10,
padding_right = 10,
},
knob = {
string = "",
drawing = true,
},
},
})
local volume_item = sbar.add("item", "volume_item", {
position = "right",
icon = {
string = icons.volume._100,
padding_left = 10,
padding_right = 10,
font = {
style = settings.font.style_map["Semibold"],
size = settings.font.size,
},
},
label = {
string = "??%",
padding_right = settings.padding.icon_label_item.label.padding_right,
font = { family = settings.font.numbers },
},
})
volume_slider:subscribe("mouse.clicked", function(env)
sbar.exec("osascript -e 'set volume output volume " .. env["PERCENTAGE"] .. "'")
end)
volume_slider:subscribe("volume_change", function(env)
local volume = tonumber(env.INFO)
local icon = icons.volume._0
if volume > 60 then
icon = icons.volume._100
elseif volume > 30 then
icon = icons.volume._66
elseif volume > 10 then
icon = icons.volume._33
elseif volume > 0 then
icon = icons.volume._10
end
local lead = ""
if volume < 10 then
lead = "0"
end
--
volume_item:set({ icon = icon })
volume_item:set({ label = { string = lead .. volume .. "%" } })
volume_slider:set({ slider = { percentage = volume } })
end)
local function animate_slider_width(width)
sbar.animate("tanh", 30.0, function()
if width == 0 then
volume_slider:set({ drawing = false, slider = { width = width } })
else
volume_slider:set({ drawing = true, slider = { width = width } })
end
end)
end
volume_item:subscribe("mouse.clicked", function()
if tonumber(volume_slider:query().slider.width) > 0 then
animate_slider_width(0)
else
animate_slider_width(100)
end
end)
Curious thing. If I cannot Airpods to Macbook volume widget works as expected :/