You could use interactive to test if R is running in interactive mode. interactive will return FALSE under Rscript and TRUE under (most?) GUIs.
interactive
FALSE
TRUE