An action can not use logic and to do do that requires the use of logic. That process would need to be scripted. If you have programming skills and knowledge of Photoshop. You could learn Photoshop scripting and program your process.
This was mostly covered in my reply to this topic:
This should be easily done with a simple batch action, no need for a script unless I am missing something.
The action steps will be pretty simple:
Presuming that your variable “frame” layers have a single true layer and not a flattened Background image:
1) Set current layer to screen blending mode
2) Place (the common static background image)
3) Move current layer to back layer (using keyboard shortcut)
When run as a batch, the exisiting variable frame image will have it’s layer mode set screen, next the static background image is placed and then moved behind the variable layer.
This should create 499 layered files, each with the same static background with a variable layer above it.
Actually since he wants to create a timelapse movie he is making the process much harder than it need be. The whole thing could simply be done by loading his 499 frame images into a stack. Change all layers blending mode to screen. Create a frame animation. Use fly-out menu item make frame from layers. Check New layer appear in all frames in the fly-out menu options. Then place in their background on the bottom of the layer stack. Select all Frames set some time duration Then export the timelapse video or frame animation.
I do have a requirement that each sub-frame be available for any other purpose.
So while I did try the stack/frame animation method, and I appreciate the response I am on the other track.
With regards to the batch process, I got a weird result. It seemed to only process every second file. So my solutions was to run it twice. Once on the first file, and once on the second file. I end up where I want to be, but with a strange requirement to run the process twice!
thanks very much