I dont think there is a way to script this. However, you could have a file where you store all the colors either as layout objects such as rectangles. Then you could quickly click on each one to add back to your custom color pallette.
Many of us have been asking for the ability for custom pallettes for a while. I would like it to be even one step further and have the ability to save color swatches like most design applications. This way we could load save and load different swatches for various projects or particular layouts.
I have already sumitted this request numerous times over the years but the more times it it requested from people the better chance that it may be considered so I highly suggest that you also submit the request.
Please submit your request here.
Thank you for the suggestions; I do something similar already, but it seems like a poor use of time on my part (and others, as I've gathered). I contributed a comment to the 'add this feature' link that you provided. I can only cross my fingers after this point...