@peternlewis, here is a JavaScript by @ComplexPoint that is also failing to maintain the selection of a code block after the script completes:
[Select and copy code (JavaScript)]
(Need Macro/JavaScript to Extract Contents of Code Block - #11 by ComplexPoint)
I've run a bunch more tests on the SD Forum, and all of the scripts work properly there.
How do we tell which version of Discourse a forum is running?