5

I have connected TV to my PC thru HDMI port. Every time I turn on my PC i need to change in pavucontrol (in config tab) from (HDMI) to (HDMI 3). I wish to make a bash script which can change it for me.

Here's how it looks in pavucontrol:

Output of pacmd list_sinks command before and after change in pavucontrol:

pacmd list_sinks before changing:

3 sink(s) available.
    index: 0
    name: <alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9049
    volume: front-left: 65886 / 101% / 0,14 dB,   front-right: 65886 / 101% / 0,14 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 45,38 ms
    max request: 6 KiB
    max rewind: 344 KiB
    monitor source: 0
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 2000,00 ms
    card: 0 <alsa_card.usb-C-Media_Electronics_Inc._USB_Audio_Device-00>
    module: 6
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "USB Audio"
        alsa.id = "USB Audio"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "2"
        alsa.card_name = "USB Audio Device"
        alsa.long_card_name = "C-Media Electronics Inc. USB Audio Device at usb-0000:01:00.0-10, full speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:01:00.0-usb-0:10:1.0"
        sysfs.path = "/devices/pci0000:00/0000:00:01.3/0000:01:00.0/usb1/1-10/1-10:1.0/sound/card2"
        udev.id = "usb-C-Media_Electronics_Inc._USB_Audio_Device-00"
        device.bus = "usb"
        device.vendor.id = "0d8c"
        device.vendor.name = "C-Media Electronics, Inc."
        device.product.id = "0012"
        device.product.name = "USB Audio Device"
        device.serial = "C-Media_Electronics_Inc._USB_Audio_Device"
        device.string = "front:2"
        device.buffering.buffer_size = "352800"
        device.buffering.fragment_size = "176400"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analogowe stereo"
        device.description = "USB Audio Device Analogowe stereo"
        alsa.mixer_name = "USB Mixer"
        alsa.components = "USB0d8c:0012"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    ports:
        analog-output-speaker: Głośniki (priority 10000, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-speakers"
    active port: <analog-output-speaker>
  * index: 2
    name: <alsa_output.pci-0000_0a_00.3.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9059
    volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 31,46 ms
    max request: 6 KiB
    max rewind: 64 KiB
    monitor source: 3
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 371,52 ms
    card: 2 <alsa_card.pci-0000_0a_00.3>
    module: 8
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "ALC887-VD Analog"
        alsa.id = "ALC887-VD Analog"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "1"
        alsa.card_name = "HD-Audio Generic"
        alsa.long_card_name = "HD-Audio Generic at 0xfd700000 irq 58"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:0a:00.3"
        sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:0a:00.3/sound/card1"
        device.bus = "pci"
        device.vendor.id = "1022"
        device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
        device.product.id = "1457"
        device.string = "front:1"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analogowe stereo"
        device.description = "HD-Audio Generic Analogowe stereo"
        alsa.mixer_name = "Realtek ALC887-VD"
        alsa.components = "HDA:10ec0887,1458a182,00100302"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        analog-output-lineout: Wyjście liniowe (priority 9900, latency offset 0 usec, available: yes)
            properties:

        analog-output-headphones: Słuchawki (priority 9000, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-headphones"
    active port: <analog-output-lineout>
    index: 7
    name: <alsa_output.pci-0000_08_00.1.hdmi-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9050
    volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 39,91 ms
    max request: 6 KiB
    max rewind: 64 KiB
    monitor source: 8
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 371,52 ms
    card: 1 <alsa_card.pci-0000_08_00.1>
    module: 7
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "HDMI 0"
        alsa.id = "HDMI 0"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "3"
        alsa.card = "0"
        alsa.card_name = "HDA NVidia"
        alsa.long_card_name = "HDA NVidia at 0xfd080000 irq 56"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:08:00.1"
        sysfs.path = "/devices/pci0000:00/0000:00:03.1/0000:08:00.1/sound/card0"
        device.bus = "pci"
        device.vendor.id = "10de"
        device.vendor.name = "NVIDIA Corporation"
        device.product.id = "0fb9"
        device.string = "hdmi:0"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "hdmi-stereo"
        device.profile.description = "Digital Stereo (HDMI)"
        device.description = "HDA NVidia Digital Stereo (HDMI)"
        alsa.mixer_name = "Nvidia GPU 80 HDMI/DP"
        alsa.components = "HDA:10de0080,104385c7,00100100"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: yes)
            properties:
                device.icon_name = "video-display"
                device.product.name = "E2240
       "
    active port: <hdmi-output-0>

pacmd list_sinks after change:

3 sink(s) available.
    index: 0
    name: <alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9049
    volume: front-left: 65886 / 101% / 0,14 dB,   front-right: 65886 / 101% / 0,14 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 45,35 ms
    max request: 6 KiB
    max rewind: 344 KiB
    monitor source: 0
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 2000,00 ms
    card: 0 <alsa_card.usb-C-Media_Electronics_Inc._USB_Audio_Device-00>
    module: 6
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "USB Audio"
        alsa.id = "USB Audio"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "2"
        alsa.card_name = "USB Audio Device"
        alsa.long_card_name = "C-Media Electronics Inc. USB Audio Device at usb-0000:01:00.0-10, full speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:01:00.0-usb-0:10:1.0"
        sysfs.path = "/devices/pci0000:00/0000:00:01.3/0000:01:00.0/usb1/1-10/1-10:1.0/sound/card2"
        udev.id = "usb-C-Media_Electronics_Inc._USB_Audio_Device-00"
        device.bus = "usb"
        device.vendor.id = "0d8c"
        device.vendor.name = "C-Media Electronics, Inc."
        device.product.id = "0012"
        device.product.name = "USB Audio Device"
        device.serial = "C-Media_Electronics_Inc._USB_Audio_Device"
        device.string = "front:2"
        device.buffering.buffer_size = "352800"
        device.buffering.fragment_size = "176400"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analogowe stereo"
        device.description = "USB Audio Device Analogowe stereo"
        alsa.mixer_name = "USB Mixer"
        alsa.components = "USB0d8c:0012"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    ports:
        analog-output-speaker: Głośniki (priority 10000, latency offset 0 usec, available: unknown)
            properties:
                device.icon_name = "audio-speakers"
    active port: <analog-output-speaker>
  * index: 2
    name: <alsa_output.pci-0000_0a_00.3.analog-stereo>
    driver: <module-alsa-card.c>
    flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9059
    volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 38,88 ms
    max request: 6 KiB
    max rewind: 64 KiB
    monitor source: 3
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 371,52 ms
    card: 2 <alsa_card.pci-0000_0a_00.3>
    module: 8
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "ALC887-VD Analog"
        alsa.id = "ALC887-VD Analog"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "0"
        alsa.card = "1"
        alsa.card_name = "HD-Audio Generic"
        alsa.long_card_name = "HD-Audio Generic at 0xfd700000 irq 58"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:0a:00.3"
        sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:0a:00.3/sound/card1"
        device.bus = "pci"
        device.vendor.id = "1022"
        device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
        device.product.id = "1457"
        device.string = "front:1"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "analog-stereo"
        device.profile.description = "Analogowe stereo"
        device.description = "HD-Audio Generic Analogowe stereo"
        alsa.mixer_name = "Realtek ALC887-VD"
        alsa.components = "HDA:10ec0887,1458a182,00100302"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        analog-output-lineout: Wyjście liniowe (priority 9900, latency offset 0 usec, available: yes)
            properties:

        analog-output-headphones: Słuchawki (priority 9000, latency offset 0 usec, available: no)
            properties:
                device.icon_name = "audio-headphones"
    active port: <analog-output-lineout>
    index: 6
    name: <alsa_output.pci-0000_08_00.1.hdmi-stereo-extra2>
    driver: <module-alsa-card.c>
    flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
    state: IDLE
    suspend cause: 
    priority: 9050
    volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
            balance 0,00
    base volume: 65536 / 100% / 0,00 dB
    volume steps: 65537
    muted: no
    current latency: 30,36 ms
    max request: 6 KiB
    max rewind: 64 KiB
    monitor source: 7
    sample spec: s16le 2 k 44100 Hz
    channel map: front-left,front-right
                 Stereo
    used by: 0
    linked by: 1
    configured latency: 40,00 ms; range is 0,50 .. 371,52 ms
    card: 1 <alsa_card.pci-0000_08_00.1>
    module: 7
    properties:
        alsa.resolution_bits = "16"
        device.api = "alsa"
        device.class = "sound"
        alsa.class = "generic"
        alsa.subclass = "generic-mix"
        alsa.name = "HDMI 2"
        alsa.id = "HDMI 2"
        alsa.subdevice = "0"
        alsa.subdevice_name = "subdevice #0"
        alsa.device = "8"
        alsa.card = "0"
        alsa.card_name = "HDA NVidia"
        alsa.long_card_name = "HDA NVidia at 0xfd080000 irq 56"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:08:00.1"
        sysfs.path = "/devices/pci0000:00/0000:00:03.1/0000:08:00.1/sound/card0"
        device.bus = "pci"
        device.vendor.id = "10de"
        device.vendor.name = "NVIDIA Corporation"
        device.product.id = "0fb9"
        device.string = "hdmi:0,2"
        device.buffering.buffer_size = "65536"
        device.buffering.fragment_size = "32768"
        device.access_mode = "mmap+timer"
        device.profile.name = "hdmi-stereo-extra2"
        device.profile.description = "Digital Stereo (HDMI 3)"
        device.description = "HDA NVidia Digital Stereo (HDMI 3)"
        alsa.mixer_name = "Nvidia GPU 80 HDMI/DP"
        alsa.components = "HDA:10de0080,104385c7,00100100"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    ports:
        hdmi-output-2: HDMI / DisplayPort 3 (priority 5700, latency offset 0 usec, available: yes)
            properties:
                device.icon_name = "video-display"
                device.product.name = "LG TV
       "
    active port: <hdmi-output-2>

pactl list cards output:

 
0. karta
    Nazwa: alsa_card.usb-C-Media_Electronics_Inc._USB_Audio_Device-00
    Sterownik: module-alsa-card.c
    Właściciel modułu: 6
    Właściwości:
        alsa.card = "2"
        alsa.card_name = "USB Audio Device"
        alsa.long_card_name = "C-Media Electronics Inc. USB Audio Device at usb-0000:01:00.0-10, full speed"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:01:00.0-usb-0:10:1.0"
        sysfs.path = "/devices/pci0000:00/0000:00:01.3/0000:01:00.0/usb1/1-10/1-10:1.0/sound/card2"
        udev.id = "usb-C-Media_Electronics_Inc._USB_Audio_Device-00"
        device.bus = "usb"
        device.vendor.id = "0d8c"
        device.vendor.name = "C-Media Electronics, Inc."
        device.product.id = "0012"
        device.product.name = "USB Audio Device"
        device.serial = "C-Media_Electronics_Inc._USB_Audio_Device"
        device.string = "2"
        device.description = "USB Audio Device"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-usb"
    Profile:
        input:analog-mono: Wejście Analogowe mono (odpływy: 0, źródła: 1, priorytet: 2, dostępne: tak)
        output:analog-stereo: Wyjście Analogowe stereo (odpływy: 1, źródła: 0, priorytet: 6000, dostępne: tak)
        output:analog-stereo+input:analog-mono: Wyjście Analogowe stereo + Wejście Analogowe mono (odpływy: 1, źródła: 1, priorytet: 6002, dostępne: tak)
        output:iec958-stereo: Wyjście Cyfrowe stereo (IEC958) (odpływy: 1, źródła: 0, priorytet: 5500, dostępne: tak)
        output:iec958-stereo+input:analog-mono: Wyjście Cyfrowe stereo (IEC958) + Wejście Analogowe mono (odpływy: 1, źródła: 1, priorytet: 5502, dostępne: tak)
        off: Wyłączone (odpływy: 0, źródła: 0, priorytet: 0, dostępne: tak)
    Aktywny profil: output:analog-stereo+input:analog-mono
    Porty:
        analog-input-mic: Mikrofon (priority: 8700, latency offset: 0 usec)
            Właściwości:
                device.icon_name = "audio-input-microphone"
            Część profilu: input:analog-mono, output:analog-stereo+input:analog-mono, output:iec958-stereo+input:analog-mono
        analog-output-speaker: Głośniki (priority: 10000, latency offset: 0 usec)
            Właściwości:
                device.icon_name = "audio-speakers"
            Część profilu: output:analog-stereo, output:analog-stereo+input:analog-mono
        iec958-stereo-output: Wyjście cyfrowe (S/PDIF) (priority: 0, latency offset: 0 usec)
            Część profilu: output:iec958-stereo, output:iec958-stereo+input:analog-mono

1. karta
    Nazwa: alsa_card.pci-0000_08_00.1
    Sterownik: module-alsa-card.c
    Właściciel modułu: 7
    Właściwości:
        alsa.card = "0"
        alsa.card_name = "HDA NVidia"
        alsa.long_card_name = "HDA NVidia at 0xfd080000 irq 56"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:08:00.1"
        sysfs.path = "/devices/pci0000:00/0000:00:03.1/0000:08:00.1/sound/card0"
        device.bus = "pci"
        device.vendor.id = "10de"
        device.vendor.name = "NVIDIA Corporation"
        device.product.id = "0fb9"
        device.string = "0"
        device.description = "HDA NVidia"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    Profile:
        output:hdmi-stereo: Wyjście Digital Stereo (HDMI) (odpływy: 1, źródła: 0, priorytet: 5400, dostępne: tak)
        output:hdmi-stereo-extra1: Wyjście Digital Stereo (HDMI 2) (odpływy: 1, źródła: 0, priorytet: 5200, dostępne: tak)
        output:hdmi-surround-extra1: Wyjście Digital Surround 5.1 (HDMI 2) (odpływy: 1, źródła: 0, priorytet: 100, dostępne: tak)
        output:hdmi-surround71-extra1: Wyjście Digital Surround 7.1 (HDMI 2) (odpływy: 1, źródła: 0, priorytet: 100, dostępne: tak)
        output:hdmi-stereo-extra2: Wyjście Digital Stereo (HDMI 3) (odpływy: 1, źródła: 0, priorytet: 5200, dostępne: tak)
        output:hdmi-surround-extra2: Wyjście Digital Surround 5.1 (HDMI 3) (odpływy: 1, źródła: 0, priorytet: 100, dostępne: tak)
        off: Wyłączone (odpływy: 0, źródła: 0, priorytet: 0, dostępne: tak)
    Aktywny profil: output:hdmi-stereo
    Porty:
        hdmi-output-0: HDMI / DisplayPort (priority: 5900, latency offset: 0 usec, available)
            Właściwości:
                device.icon_name = "video-display"
                device.product.name = "E2240
       "
            Część profilu: output:hdmi-stereo
        hdmi-output-1: HDMI / DisplayPort 2 (priority: 5800, latency offset: 0 usec, not available)
            Właściwości:
                device.icon_name = "video-display"
            Część profilu: output:hdmi-stereo-extra1, output:hdmi-surround-extra1, output:hdmi-surround71-extra1
        hdmi-output-2: HDMI / DisplayPort 3 (priority: 5700, latency offset: 0 usec, available)
            Właściwości:
                device.icon_name = "video-display"
                device.product.name = "LG TV
       "
            Część profilu: output:hdmi-stereo-extra2, output:hdmi-surround-extra2

2. karta
    Nazwa: alsa_card.pci-0000_0a_00.3
    Sterownik: module-alsa-card.c
    Właściciel modułu: 8
    Właściwości:
        alsa.card = "1"
        alsa.card_name = "HD-Audio Generic"
        alsa.long_card_name = "HD-Audio Generic at 0xfd700000 irq 58"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:0a:00.3"
        sysfs.path = "/devices/pci0000:00/0000:00:08.1/0000:0a:00.3/sound/card1"
        device.bus = "pci"
        device.vendor.id = "1022"
        device.vendor.name = "Advanced Micro Devices, Inc. [AMD]"
        device.product.id = "1457"
        device.string = "1"
        device.description = "HD-Audio Generic"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"
    Profile:
        input:analog-stereo: Wejście Analogowe stereo (odpływy: 0, źródła: 1, priorytet: 60, dostępne: tak)
        output:analog-stereo: Wyjście Analogowe stereo (odpływy: 1, źródła: 0, priorytet: 6000, dostępne: tak)
        output:analog-stereo+input:analog-stereo: Analogowy dupleks stereo (odpływy: 1, źródła: 1, priorytet: 6060, dostępne: tak)
        output:iec958-stereo: Wyjście Cyfrowe stereo (IEC958) (odpływy: 1, źródła: 0, priorytet: 5500, dostępne: tak)
        output:iec958-stereo+input:analog-stereo: Wyjście Cyfrowe stereo (IEC958) + Wejście Analogowe stereo (odpływy: 1, źródła: 1, priorytet: 5560, dostępne: tak)
        off: Wyłączone (odpływy: 0, źródła: 0, priorytet: 0, dostępne: tak)
    Aktywny profil: output:analog-stereo
    Porty:
        analog-input-front-mic: Przedni mikrofon (priority: 8500, latency offset: 0 usec, not available)
            Właściwości:
                device.icon_name = "audio-input-microphone"
            Część profilu: input:analog-stereo, output:analog-stereo+input:analog-stereo, output:iec958-stereo+input:analog-stereo
        analog-input-rear-mic: Tylny mikrofon (priority: 8200, latency offset: 0 usec, not available)
            Właściwości:
                device.icon_name = "audio-input-microphone"
            Część profilu: input:analog-stereo, output:analog-stereo+input:analog-stereo, output:iec958-stereo+input:analog-stereo
        analog-input-linein: Wejście liniowe (priority: 8100, latency offset: 0 usec, not available)
            Część profilu: input:analog-stereo, output:analog-stereo+input:analog-stereo, output:iec958-stereo+input:analog-stereo
        analog-output-lineout: Wyjście liniowe (priority: 9900, latency offset: 0 usec, available)
            Część profilu: output:analog-stereo, output:analog-stereo+input:analog-stereo
        analog-output-headphones: Słuchawki (priority: 9000, latency offset: 0 usec, not available)
            Właściwości:
                device.icon_name = "audio-headphones"
            Część profilu: output:analog-stereo, output:analog-stereo+input:analog-stereo
        iec958-stereo-output: Wyjście cyfrowe (S/PDIF) (priority: 0, latency offset: 0 usec)
            Część profilu: output:iec958-stereo, output:iec958-stereo+input:analog-stereo

How can I achieve that?

2 Answers2

2

Each time you reboot Pulse Audio resets sound device to HDMI. In order for it to keep the setting at HDMI3 you need to tell it to stop automatically switching.

Disable automatic device switching

When signal is lost to during sleep or shutdown, Pulse Audio is automatically configured to activate the default source (your HDMI). Upon resume or restart the sound device is still on HDMI. To override this setting, tell Pulse Audio to never switch sound devices automatically:

  • edit the file /etc/pulse/default.pa
  • find the line load-module module-switch-on-port-available
  • insert a # at the beginning of the line to disable automatic port switching
  • save the file and reboot.

Instead of rebooting you can use pulseaudio -k to reload the configuration changes.

1

(The accepted answer fixes the user's specific problem, but does not answer the original question "how to edit PulseAudio configuration through a script")

To change the PulseAudio configuration via terminal use the command:

pacmd set-card-profile <card> <new-profile>

where <card> is the index or the name of the target card (HDA Nvidia in your case). To get the card and profile names use pacmd:

$ pacmd list-sinks
card: 1 <alsa_card.pci-0000_08_00.1>
...
  properties:
    device.profile.name = "hdmi-stereo" # Before
    device.profile.name = "hdmi-stereo-extra2" # After
...

$ pacmd list-cards name: alsa_card.pci-0000_08_00.1 ... Profile: output:hdmi-stereo: <display name> output:hdmi-stereo-extra2: <display name> # Target profile ...

In your case it would be:

pacmd set-card-profile alsa_card.pci-0000_08_00.1 output:hdmi-stereo-extra2

pdpino
  • 111