Ask Your Question
0

How to create Sound Settings launcher?

asked 2018-03-01 15:55:19 -0500

wolfv gravatar image

updated 2018-03-03 14:23:04 -0500

I need to quickly switch from speakers to headphone when my PC receives an incoming phone call. Is there a way to create a launcher for Gnome Sound Settings (right-click on Desktop > Settings > Sound)? The launcher would go on my task bar.

This one-click solution would be even better: a script to launch Sound Settings, select Headphones, and set Volume.

I have tried "sound-output-device-chooser" but it takes 2 clicks to switch to headphone, and then two more clicks to go back in and adjust the volume.

Thank you.

edit retag flag offensive close merge delete

Comments

Just an idea, pactl a command line tool for controlling pulseaudio.

fcomida gravatar imagefcomida ( 2018-03-02 13:00:30 -0500 )edit

@fcomida, Interesting. Do you think adapting this is the way to go: https://wiki.archlinux.org/index.php/...bothspeakersandheadphonespluggedinandswitchinginsoftware_on-the-fly

wolfv gravatar imagewolfv ( 2018-03-02 16:36:20 -0500 )edit

It's a good starting point (I love arch extensive documentation). Play with it ftom the command line, when it works put all commands in a script, make it executable, create a .desktop file for it (via gui or editor) in the right place and you are done.

fcomida gravatar imagefcomida ( 2018-03-02 17:19:50 -0500 )edit

@fcomida, That's encouraging. How to have script open the Gnome Sound Settings? At start of phone call, Sound Settings would be used to adjust the volume. And after the phone call, Sound Settings would be used to restore previous speakers and volume.

wolfv gravatar imagewolfv ( 2018-03-02 19:50:06 -0500 )edit

@wolfv no gui, no launching Sound Settings, you control PulseAudio sending it commands via pactl so you can mute/unmute/adjust volume, switching output and so on. I'm not really into this kind of stuff, read pactl man page and Arch wiki for figuring out yourself. By the way, how your telephone set up is done? You mentioned: "...when my PC receives an incoming phone call".

fcomida gravatar imagefcomida ( 2018-03-02 20:51:36 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-03-11 03:34:56 -0500

wolfv gravatar image

updated 2018-03-11 11:24:28 -0500

Thanks to fcomida for pointing me to pactl.

Here is the final product, switch_sound.sh:

#!/bin/bash

################################### license ##################################
# switch_sound.sh is a script that switches between speaker and headphone with one mouse click.
# Written in 2018 by Wolfram Volpi, contact at https://gist.github.com/wolfv6/df6deb2ac7667d16d621d6da79ef99e0
# To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.
# This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with this software.
# If not, see http://creativecommons.org/publicdomain/zero/1.0/.

################################## Features ##################################
# One-click switch-sound to headphone, useful when PC receives an incoming phone call.
# Large pop-up reminds user to switch to speakers, to hear phone ring on next incoming call.
# One-click switch-sound to speakers.
# Tested on Linux Fedora 27, Gnome 3.26.2

############################### Setup on Gnome ###############################
# The speakers and headphones are always plugged in.
#
# https://www.systutorials.com/docs/linux/man/1-pactl/
# PulseAudio clients can send audio to "sinks" and receive audio from "sources".
# So sinks are outputs (audio goes there), sources are inputs (audio comes from there).
# pactl commands are by Tanu Kaskinen, explained by Tanu himself on
#   https://lists.freedesktop.org/archives/pulseaudio-discuss/2018-March/029623.html
#
# Edit this file's pactl commands to match your sinks
# For example, on my system, Sink #0 is speakers, and Sink #1 is headphone:
#    $ pactl list sinks
#    Sink #0
#    Name: alsa_output.usb-1130_USB_AUDIO-00.iec958-stereo
#    Ports:
#    iec958-stereo-output: Digital Output (S/PDIF) (priority: 0)
#    Sink #1
#    Name: alsa_output.pci-0000_00_1b.0.analog-stereo
#    Ports:
#    analog-output-headphones: Headphones (priority: 9000, available)
#
# Create a desktop file named switch_sound.desktop
# Call this switch_sound.sh script from switch_sound.desktop
# Add switch_sound.desktop to Favorites so it shows up on your taskbar.

#switch to the internal sound card
pactl set-card-profile alsa_card.pci-0000_00_1b.0 output:analog-stereo+input:analog-stereo
pactl set-card-profile alsa_card.usb-1130_USB_AUDIO-00 off

#open large pop-up
zenity --warning --title="Headphone is on" --text="<span size='xx-large'>Switch to speakers f

or phone ringer?</span>" --width=1000 --height=500

#when user closes pop-up, switch to the USB sound card
pactl set-card-profile alsa_card.usb-1130_USB_AUDIO-00 output:iec958-stereo
pactl set-card-profile alsa_card.pci-0000_00_1b.0 input:analog-stereo
edit flag offensive delete link more

Comments

@wolfv well done. I'd suggest you putting it on GitHub for making your script available to a broader audience.

fcomida gravatar imagefcomida ( 2018-03-11 09:31:14 -0500 )edit

Latest version of switch_sound.sh with open-source license is posted on https://gist.github.com/wolfv6/df6deb...

wolfv gravatar imagewolfv ( 2018-03-11 11:11:03 -0500 )edit
0

answered 2018-03-02 15:24:10 -0500

updated 2018-03-02 15:39:48 -0500

There's one for Ubuntu called Sound Switcher Indicator. It does work on Fedora Mate by installing the application from the source code.

edit flag offensive delete link more

Comments

Thanks davesnot here. 1000 lines of Python; unfortunately I don't know Python. https://github.com/yktoo/indicator-so...

wolfv gravatar imagewolfv ( 2018-03-02 16:32:37 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-03-01 15:55:19 -0500

Seen: 156 times

Last updated: Mar 11