summaryrefslogtreecommitdiff
path: root/mic-toggle
blob: 92c0180e426e10410bef9259ca194d1fc93e332e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash

set -euo pipefail

JACK_SOURCE=alsa_input.pci-0000_07_00.6.HiFi__hw_Generic_1__source
ALERT_TIME="1 hour"
ALERT_QUEUE=m

get_noise_torch_device_name() {
  pactl list sources short | grep NoiseTorch | awk -F '\t' '{print $2}' || return 0
}

cancel_alert() {
  atq -q "$ALERT_QUEUE" | cut -f 1 | xargs -r atrm
}

add_alert() {
  at now + "$ALERT_TIME" -q "$ALERT_QUEUE" <<<"alert 'Toggle mic'" 2>/dev/null
}

main() {
  cancel_alert
  if [ -z "$(get_noise_torch_device_name)" ]; then
    noisetorch -i "$JACK_SOURCE"
    pactl set-default-source "$(get_noise_torch_device_name)"
    pw-loopback &
    add_alert
  else
    noisetorch -u
    pkill -x pw-loopback || true
  fi
}

main