I am looking for a query or a simple program to find all the unreferneced images or assets within DAM. This will help us clean out the images that are no longer required.
The class you are looking for is com.day.cq.wcm.commons.ReferenceSearch (http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/commons/ReferenceSearch.html)
Well, I don't mind scripts, but for this task, I would never use it. I would, as Jörg also states, use a controlled servlet and utilize the great manager services that exists in CQ.