diff options
| author | sinanmohd <pcmsinan@gmail.com> | 2023-03-17 11:42:54 +0530 | 
|---|---|---|
| committer | sinanmohd <pcmsinan@gmail.com> | 2023-03-17 11:43:26 +0530 | 
| commit | 4f06cc87a2a26b3f7be22268f095c00c88bf49f9 (patch) | |
| tree | 6401008bada71f5622af6486de8dcf3afeef0d29 /.local/bin | |
| parent | aa10491d42c08cf624ca217a84a6f9f614e54e41 (diff) | |
audio_cyclesink, audio_mutemic: initial commit
mute mic and cycle between wireplumber(pipewire) audio sinks
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/audio_cyclesink | 77 | ||||
| -rwxr-xr-x | .local/bin/audio_mutemic | 15 | 
2 files changed, 92 insertions, 0 deletions
| diff --git a/.local/bin/audio_cyclesink b/.local/bin/audio_cyclesink new file mode 100755 index 0000000..52b2661 --- /dev/null +++ b/.local/bin/audio_cyclesink @@ -0,0 +1,77 @@ +#!/bin/sh + +# cycle between wireplumber(pipewire) audio sinks + +parse_sinks() +{ +	isaudio= +	isadsink= + +	while read -r line +	do +		case "$line" in +		Audio) +			isaudio=true +			;; +		├─\ Sinks:) + +			[ "$isaudio" = true ] && +				isadsink=true +			;; +		├─*:) +			[ "$isadsink" = true ] && +				break +			;; +		*) +			# skip if not inside audio sink +			[ "$isadsink" != true ] && +				continue + +			# skip "blank" lines +			[ -z "${line#│}" ] && +				continue + +			# clean up input +			line="${line#│  }" +			line="${line%%.*}" + +			sinks="${sinks}${line}:" + +			;; +		esac +	done + +	printf "%s" "${sinks%:}" +	unset isaudio isadsink +} + +cycle_sink() +{ +	read -r sinks +	default_sink= +	next_sink= + +	IFS=: +	for sink in $sinks +	do +		case "$sink" in +		\**) +			default_sink="${sinks#*   }" +			;; +		*) +			if [ -n "$default_sink" ] +			then +				next_sink="${sink#    }" +				break +			fi +			;; +		esac +	done + +	# if default sink is last one use first sink +	: "${next_sink:="${sinks%%:*}"}" + +	wpctl set-default "$next_sink" +} + +wpctl status | parse_sinks | cycle_sink diff --git a/.local/bin/audio_mutemic b/.local/bin/audio_mutemic new file mode 100755 index 0000000..1a2f01a --- /dev/null +++ b/.local/bin/audio_mutemic @@ -0,0 +1,15 @@ +#! /bin/sh + +# toggle mic mute and send notification about current state + +wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle + +command -v notify-send > /dev/null || exit +case "$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)" in +*\[MUTED\]) +	notify-send " muted" "microphone  is muted" +	;; +*) +	notify-send " unmuted" "microphone  is unmuted" +	;; +esac | 
