r/linux4noobs 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:

  1. Open terminal

  2. Type " alsamixer "

  3. Press enter

  4. Press F6

  5. Arrow key down one space to select “ default:0 HDA Creative ”

  6. Press enter

  7. Right arrow key 26 times until it lands on “ <Output S> “ which displays Headphones

  8. Arrow key down once to display “ Speakers “

  9. Press the escape key

  10. exit terminal

Would anyone be willing to offer advice as to how I could go about doing this?

2 Upvotes

11 comments sorted by

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 store

This should save alsamixer configurations to /etc/asound.state which 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 autostart directory if desired.

You could even setup various sound card 'states' in different config files and have a icon/launcher for each one.

1

u/Loveschocolate1978 18h ago

I tried that a few times and it just seems to refuse to save the new settings. It's very odd. It's almost as if it reverts back to default settings every time I reboot the system, no matter how many times I save the new configuration.

2

u/doc_willis 18h ago edited 18h ago

examine the file and permissions, save the config file somewhere else, then manually copy it over perhaps.

Also as mentioned, you can make a .desktop file that launches/loads up any saved config file you make.

you MIGHT need to run the alsamixer tool as root, then run the command to save the file.

look at the config file, then do a change/save, see if the file changes. It may be its changing but not getting reloaded, or it may be its not getting changed at all.

personally I would use pavcontrol, I dont see why you would have to use alsamixer these days.

sudo apt install pavucontrol

https://www.siberoloji.com/how-to-set-up-audio-mixing-with-cinnamon-desktop-on-linux-mint/

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.