The meat
In (some) terminals you can use a sequence like this;
printf "\e]4;3;rgb:cc/78/33\e\\"
to set the third color in the ANSI color palette to the RGB values represented by #CC7833. Can you do the opposite? Can I get the current RGB value (in any form) of the third (well, any really) color?
Why?
The reason you'd want to do this, in my case, is to be able to save the entire color table before messing it up (on purpose). I want to be able to list code in the terminal using an RGB exact color theme, call me anal. To do that I have to override the color definitions in the terminal color table, as per above.
For me the problem is now solved. But since I want to add this functionality to an existing open source project (pry) used by a lot of people I need to be able to save the current state of the color palette before setting the theme colors for the programs session and then switch them back after.
I know some terminals have this in settings and some systems have it in config files. But I need something that is general and would work across systems. Ideally all the systems that support setting them in the way above :)
Bonus
Right now the changing of colors affect the entire system, all terminal sessions, even after closing and restarting the terminal (this is using iTerm2 on OS X Mountain Lion).
If the effect could be made local, say to a sub shell, the problem would go away since the changes would die with the sub shell when the process ended. Even better since it would protect against cases where the session crashed...