Switching from speakers to headphone and back quickly

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
mttr
Level 1
Level 1
Posts: 45
Joined: Fri Mar 09, 2012 11:46 am

Switching from speakers to headphone and back quickly

Post by mttr »

#!/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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Locked

Return to “MATE”