We have an application "my-app" that is autostarted by xdg (.config/autostart/my-app.desktop). We need sound through the hdmi sound device. This is not the default device after a fresh installation. So we need to fix this, before my-app autostarts, or it will not detect the correct device.
Setting the device with wpctl set-default ID works, but my-app does not detect this because it is already running. We can not alter my-app or how it starts.
I considered also autostarting a script to set the correct device, but xdg does not support ordering among the autostarted programs, so no guarantee that this will be done before my-app.
I see that the .config/autostart/my-app.desktop file results in an autogenerated systemd user service app-my\[email protected]. I tried making a new user service /etc/systemd/user/set-default-audio.service to do the audio config, and juggling the systemd dependency statements so that it has to run before the autogenerated one, but without success - I can not get it to run on login. Should it be possible to do it this way?
I have considered doing the audio configuration at boot rather than login, but the problem is that all the pipewire stuff seems to be starting as --user systemd services, and hence none of it is running before we log in.
Is there a different way to automatically make our audio configured properly before our my-app autostarts? This must be working on first login after our automatic installation has run.
We're running RHEL9.2.
/etc/systemd/user/set-default-audio.servicedoes not automatically make it start. It needs to be pulled (e.g. wanted bydefault.targetand enabled).WantedBy=, but basically just anything that has also been "enabled", and as I saiddefault.targetwould be a good candidate.after pipewireSo obviously you also needAfter=wireplumber.service. (You don't needRequires=wireplumber.serviceas long as you have that and pipewire.service enabled.) Also check whether you actuallycan not get it to run on loginor if the command failed for reasons.[Install]section, andsystemctl --user daemon-reloadand re-enable it afterwards.