Linux: script for resetting the audio output

When you start your Kubuntu computer and the audio jack cable is not plugged, then no audio will be selected. After having plugged it, you will have to go to the sound settings and set the right audio output. The following script will automatically select the analogic output, which is quicker. You’ll need first to specify which card and profiles you want to use.

#!/usr/bin/env bash

# use the command "pactl list cards" to find the card you want, and put its alsa name below.
card_name="HD-Audio Generic"
# still in "pactl list cards", choose the output profile you want

card=$(pactl -f json list cards | jq --arg card_name "$card_name" '.[] | select(.properties["alsa.card_name"]==$card_name).index')
if [ -z "$card" ];then
    >&2 echo "Error: Could not find searched card"
    exit 1

pactl set-card-profile "$card" "$profile"

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *