Physical Representation of Colours in a Document (Color Bars)

Hello,
I work in a business where we create print cards for each job we produce. Sometimes we're requested to list all the colours, spot colours and varnish types used and they would like it presented like the attached image here.
I remember spending time at a business where the artist there had a script that would access all the colours in an Illustrator Layer called "Artwork" it would then spit out pretty much exactly what the attached image is - each colour in a square + text below it that says the name of the text. I believe it was either a text or an action, I'm not sure. Unfortunately that artist is no longer with us anymore.
From memory, whatever it was only listed the colours from a layer called "Artwork" there were other layers but it didn't list any of the colours in them.
I'd like to know what something like this would be? An action? A script? And is it possible to create?
Thanks