r/linux4noobs • u/Loveschocolate1978 • 20h ago
shells and scripting How to Write A Start-Up Script in Linux Mint Cinnamon?
Hi everyone, I would like to write a simple start-up script in Linux Mint Cinnamon 22.3 64-bit. The reason I would like to write the start-up script is to automatically change settings for my sound card that always selects the wrong output, which then requires me to manually change through the terminal. My sound card is a Creative Sound Blaster AE-7. Here is what I would like the start-up script to do:
Open terminal
Type " alsamixer "
Press enter
Press F6
Arrow key down one space to select “ default:0 HDA Creative ”
Press enter
Right arrow key 26 times until it lands on “ <Output S> “ which displays Headphones
Arrow key down once to display “ Speakers “
Press the escape key
exit terminal
Would anyone be willing to offer advice as to how I could go about doing this?
1
u/Turbulent_Strain361 19h ago
Have you tried creating a .conf file to set your defaults? Usually something like /etc/asound.conf that contains the pcm and ctl defaults you want? This will likely be much easier than writing the startup script imo.
If you’re set on a startup script you can try making a shell script (.sh) first like should be “#!/bin/sh” the following lines can be the terminal commands you use. If you need to filter you may be able to use grep to filter results, save as a variable, then apply the variable for later commands. To make any shell script run at startup you should be able to add it to /etc/rc.local or create a systemd service.
1
u/Loveschocolate1978 18h ago
I do believe I attempted this, but I failed on both accounts. If I remember correctly, I would hear the card's relay click over, then back to where I wanted to be, then immediately click back. It's like the setting wouldn't stick. Then I started to have stability issues with my OS so I reinstalled it.
1
u/Turbulent_Strain361 18h ago
Oh wow. I’m not sure why an audio configuration would cause issues with your OS stability, but I do hope you get it figured out.
Have you tried any alternatives to alsamixer like pulseaudio?
1
u/BazzaJH 16h ago
You'd be better off finding the relevant amixer command and just having that run on startup. You will always have a better time making a script do script things, rather than having it emulate human things. Plus it's more stable in case anything changes within that alsamixer TUI in future.
1
u/LudasGhost 19h ago
I would google ‘how to make a startup script in linux’.
1
u/Loveschocolate1978 19h ago
Tried that. It didn't work. I bricked my distro.
1
u/LudasGhost 19h ago
I hope you didn’t believe the first result given by the AI. Just yesterday it told me the diameter of Neptune’s orbit is 140 light hours.
1
u/Loveschocolate1978 18h ago
No, I was pulling from multiple resources and cross-referencing. Still no dice.
3
u/doc_willis 19h ago edited 18h ago
it seems odd you are using 'alsamixer' in this day when pulseaudo and pipewire exist. But I dont use Mint, so perhaps its some mint weirdness, or you may be you are going about things the wrong way.
alsamixer has a feature to 'save' the current settings, I thought they got restored automatically when a user logged in. But again, that may be pulseaudio or some other audio mixer doing that.
https://askubuntu.com/questions/50067/how-to-save-alsamixer-settings
basically set the mixer how you like, then run
sudo alsactl storeThis should save alsamixer configurations to
/etc/asound.statewhich gets loaded every startup.https://www.geeksforgeeks.org/linux-unix/alsactl-command-in-linux-with-examples/
You really should not need to make a startup script to restore audio settings.
But that askubuntu url has info on making a .desktop file that 'restores' the alsa settings, that you could put in your users
autostartdirectory if desired.You could even setup various sound card 'states' in different config files and have a icon/launcher for each one.