You probably just need to change the script context to the Rhino document before calling the unselect/select rhinoscriptsyntax functions: