Switching from speakers to headphone and back quickly

Forum rules
Before you post please read how to get help
Post Reply
mttr
Level 1
Level 1
Posts: 11
Joined: Fri Mar 09, 2012 11:46 am

Switching from speakers to headphone and back quickly

Post by mttr » Wed Mar 07, 2018 4:17 pm

#!/bin/bash

# This toggles the line-out to headphones and vice versa
# Linux Mint Mate 18.3 Tested and Works
# Save this as a script file and make sure it is set to "Allow executing file as a program" in the permissions
# Create a launcher and put on panel to use it.
#
# There is a hidden char in front of __active port: <analog-output>"*" so you have to include it
# Find which output is the active one
test_output=$(pacmd info | grep -i " active port: <analog-output>"*)

if [[ "$test_output" = " active port: <analog-output-lineout>" ]] ; then
pacmd set-sink-port 1 "analog-output-headphones" ;

elif [[ "$test_output" = " active port: <analog-output-headphones>" ]] ; then
pacmd set-sink-port 1 "analog-output-lineout" ;

fi

# commands I have use to figure this out (don't use root)
# don't include the following in script
$ pacmd info | grep -i "active"
active port: <hdmi-output-0>
active port: <analog-output-headphones>
active profile: <output:hdmi-surround>
active profile: <output:analog-stereo>

me@mint-18 ~/Desktop $ ./headphone
active port: <analog-output-headphones> (notice the extra tab or space at the beginning of this output line)
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-lineout>
$ pacmd info | grep -i "active port: <analog-output-"*
active port: <analog-output-headphones>
Headphone.rtf
raw script file and instruction
(1.33 KiB) Downloaded 61 times

Post Reply

Return to “MATE”