I've found that if I had only 1 file selected & tried to invert, MC would select everything. (Explorer mode not TC mode).
I reported seeing this 'error' here back in 2013, so Mathias does know about this.
My work-around has been to select 2 files > invert selection > use ctrl to add or subtract the 'extra' file to/from the selection.
pncdaspropagandas I shall now be trying your script, thanks for writing that.