diff options
-rw-r--r-- | README.md | 42 | ||||
-rw-r--r-- | images/sound_change.gif | bin | 0 -> 2028408 bytes | |||
-rwxr-xr-x | rofi-sound-output-chooser | 38 |
3 files changed, 80 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..bf5bc3f --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# rofi-sound-output-chooser + +## Introduction +I wanted a way to quickly switch between my bluetooth headset, and my on-board +speakers. After a little bit of poking around (and getting some inspiration +from [rofi-bluetooth](https://github.com/nickclyde/rofi-bluetooth), I came up +with this. I have not done any extensive testing. I don't know if this even +works anywhere other than my computer. I also don't know long-term if I am even +sticking with I3. I simply built this to scratch a curiosity itch with I3 and +pactl. + +![demo](images/sound_change.gif) + +## Installation + +### Dependencies + +This script requires two additional commands + +1. pactl - This is the main requirement for determining the devices +2. dunstify - Used for notifications when the device is changed. Technically + not needed, but currently there are no checks or config options to not use + it. + +For Fedora this would be done with the following: + +`dnf install pulseaudio-utils dunst` + +I don't know where any other distros keep those things, but it's probably pretty +similar to those. + +### Installing this script + +1. Clone this repo +2. Copy rofi-sound-output-chooser to somewhere in your $PATH + + +# I3wm keybinding + +I have this bound within a mode, but you could do something like + +`bindsym $mod+0 exec --no-startup-id rofi -show rofi-sound -modi "rofi-sound:rofi-sound-output-chooser"` diff --git a/images/sound_change.gif b/images/sound_change.gif Binary files differnew file mode 100644 index 0000000..6aa93cf --- /dev/null +++ b/images/sound_change.gif diff --git a/rofi-sound-output-chooser b/rofi-sound-output-chooser new file mode 100755 index 0000000..d51c71d --- /dev/null +++ b/rofi-sound-output-chooser @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Outputs have spaces in them, so let's make \n the IFS +IFS=$'\n' + +# Menu will have a quit option, though you could just escape +if [ "$*" = "quit" ] +then + exit 0 +fi + + +# An option was passed, so let's check it +if [ "$@" ] +then + # the output from the selection will be the desciption. Save that for alerts + desc="$*" + # Figure out what the device name is based on the description passed + device=$(pactl list sinks|grep -C2 "Description: $desc"|grep Name|cut -d: -f2|xargs) + # Try to set the default to the device chosen + if pactl set-default-sink "$device" + then + # if it worked, alert the user + dunstify -t 2000 -r 2 -u low "Activated: $desc" + else + # didn't work, critically alert the user + dunstify -t 2000 -r 2 -u critical "Error activating $desc" + fi +else + echo -en "\x00prompt\x1fSelect Output\n" + # Get the list of outputs based on the description, which is what makes sense to a human + # and is what we want to show in the menu + for x in $(pactl list sinks | grep -ie "description:"|cut -d: -f2) + do + # outputs with cut may have spaces, so use empty xargs to remove them, and output that to the rofi list + echo "$x"|xargs + done + echo "quit" +fi |