Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

niri/scripts/toggle-mic-preset.nu

Raw
#!/usr/bin/env -S nu --no-config-file
# Switch microphone processing without changing output presets.
let result = (^easyeffects -a input | complete)
if $result.exit_code != 0 {
    ^notify-send -a EasyEffects -u normal "Mic preset unavailable" "Could not read the current preset. Is EasyEffects running?"
    exit $result.exit_code
}
let next = if ($result.stdout | str trim) == "Fun" { "Clean" } else { "Fun" }
let loaded = (^easyeffects -l $next | complete)
let current = (^easyeffects -a input | complete)
if $loaded.exit_code != 0 or $current.exit_code != 0 or ($current.stdout | str trim) != $next {
    ^notify-send -a EasyEffects -u normal "Mic preset switch failed" $"Could not confirm preset: ($next)"
    exit 1
}
let monitoring = if $next == "Fun" { 1 } else { 2 }
let updated = (^easyeffects --microphone-monitoring $monitoring | complete)
let actual = (^easyeffects --microphone-monitoring 3 | complete)
if $updated.exit_code != 0 or $actual.exit_code != 0 or ($actual.stdout | str trim) != ($monitoring | into string) {
    ^notify-send -a EasyEffects -u normal "Mic monitoring update failed" $"Preset ($next) loaded; check input monitoring in EasyEffects."
    exit 1
}
let state = if $next == "Fun" { "on" } else { "off" }
^notify-send -a EasyEffects -u low -t 2000 -e -h string:x-canonical-private-synchronous:mic-preset $"Mic: ($next)" $"Input monitoring: ($state)"