r/linux4noobs • u/Loveschocolate1978 • 5d 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?
•
u/BazzaJH 5d 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.
•
u/Loveschocolate1978 4d ago
That sounds like a good idea for all of the reasons you stated. Do you know where I could find a list of those commands?
•
u/BazzaJH 4d ago
amixer -horamixer --helpshould list everything you need. I don't know exactly what the command would be since it will depend on your devices, but you're probably looking for something like
amixer -c 0 sset 'Output Select' 'Speakers'Might need to change the
-c 0to a different card number if it's listed differently, or you might be able to drop that part entirely if there's only one card, it should grab it by default. And just be sure that the controls are setting the same thing as you were in the interactive menu.
•
u/Turbulent_Strain361 5d 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.
•
u/Loveschocolate1978 5d 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.
•
u/Turbulent_Strain361 5d 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?
•
u/Loveschocolate1978 4d ago
I was surprised too! I think maybe I touched something else unintentionally. I had only been using linux for a few weeks at that point, so it doesn't surprise me. I haven't tried any alternatives yet because I typically like to stick with default apps as my previous experience with instability shook me a bit. Maybe it's time to try again?
•
u/Turbulent_Strain361 4d ago
Maybe it is. I have used pulseaudio and pipewire with easy effects across multiple distros and I’ve heard good things about pavucontrol. The nice thing about Linux is you’re free to use whatever you want really, you have options. Please make sure to let us know when you find the solution that works for you.
•
u/LudasGhost 5d ago
I would google ‘how to make a startup script in linux’.
•
u/Loveschocolate1978 5d ago
Tried that. It didn't work. I bricked my distro.
•
u/LudasGhost 5d 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.
•
u/Loveschocolate1978 5d ago
No, I was pulling from multiple resources and cross-referencing. Still no dice.
•
u/doc_willis 5d ago edited 5d 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.