Change the sound profile automatically when starting and ending charging When my phone isn't plugged into the charger, it's in my pocket, so vibration suffices for notifying me of a phone call or text message. But unlike my previous phone, it doesn't vibrate loudly enough for me to reliably hear it when it's not in my pocket. So I'd like to automatically change the sound profile to "Sound" when I plug in the phone, and "Vibrate only" when I unplug it. How can I do that?

I have experience in administering Linux PCs and servers, but I'm unfamiliar with Android internals, so I wouldn't know where to begin to write a shell script for this.
This needs automation or using an app (if available) , i former is preferred option for me -Macrodroid is a versatile automation app:

You would need two macros

Trigger : Power disconnected/ connected &rarr; connected

Actions: : Volume Change &rarr; set Ringer to your desired level as also others as you wish

Constraints: None (Run always) or set up your Constraints under which macro runs

For the second macro, Trigger would be power disconnected and action would be Vibrate Enable