Ubuntu automatically detects which GPU is installed in your machine. If you want a script to switch between Nvida and Intel drivers I've found one you can modify here: bauca/graphics-switcher
It will require the program glxinfo
which you can get by installing:
sudo apt install mesa-utils
One key function in the bash script that will interest you is this one:
function CheckForCurrentVideoCardInUse {
local _VIDEO_CARD=`glxinfo|egrep "OpenGL vendor|OpenGL renderer*"`
if [[ $_VIDEO_CARD == *"NVIDIA"* && $_VIDEO_CARD == *"GeForce"* ]]; then
CURRENT_VIDEO_CARD="NVIDIA"
elif [[ $_VIDEO_CARD == *"Intel"* ]]; then
CURRENT_VIDEO_CARD="INTEL"
else
ErrorHandler
fi
}