feat: sketchybar tweaks

This commit is contained in:
winston 2024-06-20 08:24:14 +02:00
parent 9c4453a964
commit 3afa78d52a
Signed by: winston
GPG key ID: 3786770EDBC2B481
5 changed files with 160 additions and 127 deletions

View file

@ -90,11 +90,14 @@ def color [name: string, alpha: float = 1.0] {
$"icon.color=(color fg)" $"icon.color=(color fg)"
$"label.color=(color fg)" $"label.color=(color fg)"
--set /space/ --set /space/
$"icon.color=(color gray 0.5)" $"icon.color=(color bgGray)"
$"icon.highlight_color=(color blue)" $"icon.highlight_color=(color blue)"
--set music --set music
$"icon.color=(color violet)" $"icon.color=(color fgGray)"
$"label.color=(color violet)" $"label.color=(color fgGray)"
--set music_progress
$"slider.highlight_color=(color blue)"
$"slider.background.color=(color bgGray)"
--set "Mullvad VPN" --set "Mullvad VPN"
$"alias.color=(color orange)" $"alias.color=(color orange)"
--set "Control Center,Battery" --set "Control Center,Battery"

View file

@ -1,25 +1,95 @@
#!/usr/bin/env nu #!/usr/bin/env nu
if (pgrep -x Music | is-not-empty) { if (pgrep -x Music | is-empty) {
let result = osascript -l JavaScript -e "
var music = Application("Music");
JSON.stringify({
albumArtist: music.currentTrack.albumArtist(),
artist: music.currentTrack.artist(),
state: music.playerState(),
track: music.currentTrack.name(),
});" | from json
let artist = if (($result.albumArtist | is-empty) or ($result.albumArtist == "Various Artists")) {
$result.artist
} else $result.albumArtist
let label = if ($result.state == "playing") {
$"($artist) - ($result.track)"
} else ""
(sketchybar (sketchybar
--set $env.NAME $"label=($label)" --set $env.NAME
icon.font="Symbols Nerd Font:2048-em:18.0" label=""
label.font="Berkeley Mono:Bold:16.0" y_offset="3") --set $"($env.NAME)-progress"
} else (sketchybar --set $env.NAME label="") slider.percentage=0
slider.width=0
)
return
}
let appleScript = '
tell application "Music"
-- set to a fixed string
if player state is playing then
set _state to "playing"
else
set _state to "paused"
end if
set _albumArtist to ""
set _trackArtist to ""
set _name to ""
set _duration to ""
set _progress to "0,0"
-- allow this to fail when Music hasnt played a track yet
try
set _albumArtist to album artist of current track
set _trackArtist to artist of current track
set _name to name of current track
set _duration to duration of current track
end try
if _albumArtist is "" or _albumArtist is "Various Artists" then
set _artist to _trackArtist
else
set _artist to _albumArtist
end if
-- wrap the progress in a try to handle division by zero
try
set _progress to player position / _duration
end try
set songData to {_state, _artist, _name, _progress}
set output to ""
repeat with _item in songData
set output to output & _item & "\n"
end repeat
end tell'
let cachePath = ($env.XDG_CACHE_HOME? | default $"($env.HOME)/.cache") | path join "apple-music-status.scpt"
# for debugging
let alwaysCompile = false
if (not ($cachePath | path exists) or $alwaysCompile) {
osacompile -o $cachePath -e $appleScript
}
let result = osascript $cachePath
| lines
| {
state: ($in.0?),
artist: ($in.1?)
track: ($in.2?)
progress: (
$in.3?
| str replace "," "."
| into float
| $in * 100.0
)
}
let label = if ($result.state == "playing") {
$"($result.artist) - ($result.track)"
} else ""
sketchybar --set $env.NAME $"label=($label)"
let width = if ($result.state == "playing") {
(sketchybar --query $env.NAME | from json).bounding_rects?.display-1?.size?.0? | default 0
} else 0
(sketchybar
--set $"($env.NAME)_progress"
$"padding_left=-($width - 7)"
$"slider.percentage=($result.progress)"
$"slider.width=($width - 20)"
)

View file

@ -0,0 +1,12 @@
#!/usr/bin/env nu
let appleScript = {|it| '
tell application "Music"
set _duration to duration of current track
set player position to (' + ($it | into string) + ' * _duration)
end tell'}
if ($env.PERCENTAGE? != null) {
osascript -e (do $appleScript (($env.PERCENTAGE | into int) / 100.0))
}

View file

@ -1,58 +0,0 @@
#!/usr/bin/env nu
let icon = match ($env.INFO?) {
# IDEs
"CLion" | "GoLand" | "PhpStorm" | "PyCharm" | RustRover | "WebStorm" | "Xcode" => " ",
"Neovide" => " ",
# developer
"Docker" => " ",
# terminals
"Kitty" | "iTerm" | "Terminal" | "WezTerm" => " ",
# browsers
"Chromium" | "Firefox" | "Safari" | "qutebrowser" => " ",
# system
"App Store" => " ",
"Books" => " ",
"Finder" => "󰀶 ",
"Music" => "󰝚 ",
"Podcasts" => " ",
"Photos" => " ",
"Preview" => " ",
"System Preferences" => " ",
# chat
"Discord" => "󰙯 ",
"Mattermost" => " ",
"Slack" => " ",
# creativity
"Affinity Designer" => "󰃣 ",
"Affinity Photo" => "󰃣 ",
"Affinity Publisher" => "󰈙 ",
"Blender" => "󰂫 ",
"Final Cut" => " ",
"Garageband" => "󰋄 ",
"Logic Pro X" => "󰋄 ",
"iMovie" => " ",
# password managers
"GPG Keychain" | "KeePassXC" | "LastPass" | "1Password" => "󰌋 ",
# other
"Audible" => "󰋋 ",
"Pocket Casts" => " ",
"Setapp" => " ",
"Spotify" => " ",
"Steam" => " ",
_ => "󰘔 ",
}
(sketchybar
--set $env.NAME $"label=($env.INFO? | default '')" $"icon=($icon)"
icon.font="Symbols Nerd Font:2048-em:18.0"
label.font="Berkeley Mono:Bold:16.0" y_offset="3")

View file

@ -1,9 +1,31 @@
#!/usr/bin/env nu #!/usr/bin/env nu
# vim:fileencoding=utf-8:foldmethod=marker # vim:fileencoding=utf-8:foldmethod=marker
let pluginDir = $env.HOME | path join ".config/sketchybar/plugins" let pluginDir = $env.XDG_CONFIG_HOME?
| default $"($env.HOME)/.config"
| path join "sketchybar/plugins"
## bar appearance {{{ let spacesCmd = ["" "Ⅱ" "Ⅲ" "Ⅳ" "" "Ⅵ" "Ⅶ" "Ⅷ" "Ⅸ" ""]
(sketchybar --bar | enumerate
| reduce --fold [] {|it, acc|
let i = $it.index + 1
$acc | append [
"--add" "space" $"space.($i)" "left"
"--set" $"space.($i)"
$"associated_space=($i)"
$"icon=($it.item)"
"icon.padding_left=8"
"icon.padding_right=8"
"background.padding_left=1"
"background.padding_right=1"
"background.height=32"
"label.drawing=off"
$"script=($pluginDir)/space.nu"
$"click_script=yabai -m space --focus ($i)"
]
}
(sketchybar
--bar
height=32 height=32
position=top position=top
padding_left=5 padding_left=5
@ -13,20 +35,17 @@ let pluginDir = $env.HOME | path join ".config/sketchybar/plugins"
border_width=0 border_width=0
hidden=off hidden=off
topmost=off topmost=off
y_offset=2) y_offset=2
# colors are managed separately in the colordummy. --add event theme_changed AppleInterfaceThemeChangedNotification
# listens to theme_changed events, to swap between dark and light mode
sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification
(sketchybar
--add item colordummy center --add item colordummy center
--set colordummy --set colordummy
drawing=off drawing=off
$"script=($pluginDir)/colordummy.nu" $"script=($pluginDir)/colordummy.nu"
--subscribe colordummy theme_changed) --subscribe colordummy theme_changed
...$spacesCmd
##### Changing Defaults #####
(sketchybar
--default --default
updates=when_shown updates=when_shown
drawing=on drawing=on
@ -35,36 +54,23 @@ sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification
label.padding_left=2 label.padding_left=2
label.padding_right=2 label.padding_right=2
icon.padding_left=2 icon.padding_left=2
icon.padding_right=2) icon.padding_right=2
# }}}
## left side of the bar {{{ --add event music_changed
# spaces for yabai wm com.apple.Music.playerInfo
for $el in ["" "Ⅱ" "Ⅲ" "Ⅳ" "" "Ⅵ" "Ⅶ" "Ⅷ" "Ⅸ" ""] --numbered {
let i = $el.index + 1
(sketchybar
--add space $"space.($i)" left
--set $"space.($i)" $"associated_space=($i)"
$"icon=($el.item)"
icon.padding_left=8
icon.padding_right=8
background.padding_left=1
background.padding_right=1
background.height=32
label.drawing=off
$"script=($pluginDir)/space.nu"
$"click_script=yabai -m space --focus ($i)")
}
sketchybar -m --add event music_changed com.apple.Music.playerInfo
(sketchybar
--add item music left --add item music left
--set music --set music
$"script=($pluginDir)/music.nu" $"script=($pluginDir)/music.nu"
label.y_offset=-1 update_freq=5
--subscribe music music_changed --subscribe music music_changed
--add slider music_progress left 100
--set music_progress
slider.background.height=2
slider.background.corner_radius=10
y_offset=-10
$"script=($pluginDir)/music_jump.nu"
--subscribe music_progress mouse.clicked
--add item clock right --add item clock right
--set clock --set clock
$"script=($pluginDir)/clock.nu" $"script=($pluginDir)/clock.nu"