feat: sketchybar tweaks
This commit is contained in:
parent
9c4453a964
commit
3afa78d52a
5 changed files with 160 additions and 127 deletions
|
@ -90,11 +90,14 @@ def color [name: string, alpha: float = 1.0] {
|
|||
$"icon.color=(color fg)"
|
||||
$"label.color=(color fg)"
|
||||
--set /space/
|
||||
$"icon.color=(color gray 0.5)"
|
||||
$"icon.color=(color bgGray)"
|
||||
$"icon.highlight_color=(color blue)"
|
||||
--set music
|
||||
$"icon.color=(color violet)"
|
||||
$"label.color=(color violet)"
|
||||
$"icon.color=(color fgGray)"
|
||||
$"label.color=(color fgGray)"
|
||||
--set music_progress
|
||||
$"slider.highlight_color=(color blue)"
|
||||
$"slider.background.color=(color bgGray)"
|
||||
--set "Mullvad VPN"
|
||||
$"alias.color=(color orange)"
|
||||
--set "Control Center,Battery"
|
||||
|
|
|
@ -1,25 +1,95 @@
|
|||
#!/usr/bin/env nu
|
||||
|
||||
if (pgrep -x Music | is-not-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
|
||||
if (pgrep -x Music | is-empty) {
|
||||
(sketchybar
|
||||
--set $env.NAME
|
||||
label=""
|
||||
--set $"($env.NAME)-progress"
|
||||
slider.percentage=0
|
||||
slider.width=0
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
let artist = if (($result.albumArtist | is-empty) or ($result.albumArtist == "Various Artists")) {
|
||||
$result.artist
|
||||
} else $result.albumArtist
|
||||
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") {
|
||||
$"($artist) - ($result.track)"
|
||||
$"($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 $"label=($label)"
|
||||
icon.font="Symbols Nerd Font:2048-em:18.0"
|
||||
label.font="Berkeley Mono:Bold:16.0" y_offset="3")
|
||||
} else (sketchybar --set $env.NAME label="")
|
||||
--set $"($env.NAME)_progress"
|
||||
$"padding_left=-($width - 7)"
|
||||
$"slider.percentage=($result.progress)"
|
||||
$"slider.width=($width - 20)"
|
||||
)
|
||||
|
|
12
home/apps/sketchybar/plugins/music_jump.nu
Executable file
12
home/apps/sketchybar/plugins/music_jump.nu
Executable 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))
|
||||
}
|
|
@ -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")
|
|
@ -1,9 +1,31 @@
|
|||
#!/usr/bin/env nu
|
||||
# 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 {{{
|
||||
(sketchybar --bar
|
||||
let spacesCmd = ["Ⅰ" "Ⅱ" "Ⅲ" "Ⅳ" "Ⅴ" "Ⅵ" "Ⅶ" "Ⅷ" "Ⅸ" "Ⅹ"]
|
||||
| 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
|
||||
position=top
|
||||
padding_left=5
|
||||
|
@ -13,20 +35,17 @@ let pluginDir = $env.HOME | path join ".config/sketchybar/plugins"
|
|||
border_width=0
|
||||
hidden=off
|
||||
topmost=off
|
||||
y_offset=2)
|
||||
y_offset=2
|
||||
|
||||
# colors are managed separately in the colordummy.
|
||||
# listens to theme_changed events, to swap between dark and light mode
|
||||
sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification
|
||||
(sketchybar
|
||||
--add event theme_changed AppleInterfaceThemeChangedNotification
|
||||
--add item colordummy center
|
||||
--set colordummy
|
||||
drawing=off
|
||||
$"script=($pluginDir)/colordummy.nu"
|
||||
--subscribe colordummy theme_changed)
|
||||
--subscribe colordummy theme_changed
|
||||
|
||||
...$spacesCmd
|
||||
|
||||
##### Changing Defaults #####
|
||||
(sketchybar
|
||||
--default
|
||||
updates=when_shown
|
||||
drawing=on
|
||||
|
@ -35,36 +54,23 @@ sketchybar -m --add event theme_changed AppleInterfaceThemeChangedNotification
|
|||
label.padding_left=2
|
||||
label.padding_right=2
|
||||
icon.padding_left=2
|
||||
icon.padding_right=2)
|
||||
# }}}
|
||||
icon.padding_right=2
|
||||
|
||||
## left side of the bar {{{
|
||||
# spaces for yabai wm
|
||||
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 event music_changed
|
||||
com.apple.Music.playerInfo
|
||||
--add item music left
|
||||
--set music
|
||||
$"script=($pluginDir)/music.nu"
|
||||
label.y_offset=-1
|
||||
update_freq=5
|
||||
--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
|
||||
--set clock
|
||||
$"script=($pluginDir)/clock.nu"
|
||||
|
|
Loading…
Reference in a new issue