A quick Google search kicked up the following script for images:
https://indesignsecrets.com/topic/sc...seperate-layer (ensure that quotes are straight, not curly)
This script is not for batch processing, it is one document at a time...
It should just take a little bit of hacking to work for...