Great blog post and example :)
Just a note to say (if others read this), that if your profile (eg, foo-bar contains a hyphen, then it doesn't work.
eg, if function colorssh() contains something like tabc foo-bar. Removing the hyphen from the profile name foo-bar in iterm2 (and updating the profile name in the function) worked for me.