What system variable can I use in the script to differentiate between ITS and GuiXT?  I would like to execute part of the script only when executed through SAP GUI.

You can use

if Q[ITS]

..

endif