Photoshop scripts

So I have two files - random pic (will always have diferent filename) and template (always the same filename). I’m taking a part of random photo and inserting it as a layer in template. The thing I want to automate is saving part. Is it possible to write a script for Photoshop that will save the template (after I’ve done my things) with the same filename as the random pic and save it in the folder that I’ve set?

Wrong thread really.

Do you know about he recording actions options in PS?

Ofcourse I know. Just read my question again. The name of first file is alaways diferent and the final filename shoud have the same name as the first file does.