I tend to have a number of terminal sessions open at the same time and for a while I have wanted a way to give each Tab in the window an informative name. You can do that through the iTerm2 preferences but I wanted a way to set it directly from the shell command line.
iTerm2 can be scripted via AppleScript and so I wrote a simple script to do the job. It uses a system application called osascript which will execute a AppleScript script from the Unix command line.
The code is freely available at https://github.com/craic/iterm_title - see the README for more details.
The code should be a useful starting point if you want to write something in AppleScript that you can call from UNIX.