Programmatically switching MacOS spaces

Is there any way to switch spaces on MacOS using code? It used to be possible by just emulating the keyboard shortcut, but now the OS ignores them. I just want to scroll between them like when you press Command-Left/Right, not necessarily select a specific desktop. Thanks
Programmatically switching MacOS spaces
 
 
Q