ALT+TAB needs to be pressed twice on first start for the script to be recognized correctly. Afterwards the script should work as intended:
Mutes the game when alt tabbing out of it. Reentering the game will unmute the game.
This script can be used for any program. Just rename RDR2.exe inside the script to any Executable you want.