Apply material from material browser to selected objects, render, save jpg image

Good Morning

I have been searching for a Max script to do the following with no luck. I was wondering if someone here can help me with this.
The scene is prepared with lights and one camera, objects are already selected in the scene with 24 materials in material browser. What I need is a script to do the steps below

1- Apply 1st material from Material browser to selected objects
2- Render the scene
3- Save the image in a directory with a name specified in the script. (The name needs to be modified in the script for each render)
4- Apply 2nd material from material browser to the same selected object
5- Render the scene
6- Save the image with the name specified in the script file
Repeat this until all materials in browser are rendered.

I appreciate any help I can get with this.

Best Regards