Added option to auto detect if scripts are run in a terminal or via GUI.