Is it possible to script a commander to cast a spell that you have not researched at the time you are scripting, but that you know you will have researched by the combat phase of the turn? Will it work?
no- you cannot select a spell you have not researched. the best you can do is to script "cast spell" using the generic command and hope they go for the right one- in some cases it works.
It depends on the spell if Immaculate's trick works. If it is a spell they would cast after the 5 rounds of scripting are over, then it will probably get cast. Otherwise, nope. (This means you can test if they will cast your spell).
As I learnt recently, if you script to cast a spell and it can't be cast (e.g. insufficient level or gems, or already cast), the mage will "substitute" not "skip". So you could do that in the script and hope he will pick a newly discovered spell...