As you state you're using a script to (re)join channels: You might add the -n switch to the script's /join commands. It will make you (re)join the channels "minimized", so they won't become the active window.
If you autojoin channels of your favorites: there's a checkbox "minimize on join" in their individual settings too.