How to programmatically update current workspace?

Sorry. Seems there is no way to get the name, so I think you’ll need to use a dummy record that saves the last opened workspace (see Script to select workspace).