refactored chooseOSCommand function