Created
May 15, 2025 00:44
-
-
Save jbrechtel/42b849dc5b37a91f70f370edadcf27da to your computer and use it in GitHub Desktop.
volume raising + lowering script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/nu | |
def main [] { | |
print "main" | |
} | |
def "main raise" [] { | |
let vol = currentVolume | |
if ($vol < 100) { | |
pactl set-sink-volume @DEFAULT_SINK@ $"($vol + 1)%" | |
print $"raised to: (currentVolume)" | |
} | |
} | |
def "main lower" [] { | |
let vol = currentVolume | |
if ($vol > 0) { | |
pactl set-sink-volume @DEFAULT_SINK@ $"($vol - 1)%" | |
print $"lowered to: (currentVolume)" | |
} | |
} | |
def currentVolume [] { | |
#Note this makes two assumptions to simplify the process | |
# 1. The left and right channels are balanced | |
# 2. There is only one active audio sink at a time (or rather that only the first active one matters) | |
let volTxt = pactl --format=json list sinks | from json | where state == "RUNNING" | first | get volume.front-left.value_percent | |
$volTxt | str substring 0..-2 | into int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment