How to bind workspace to shortcut, and also bind return to previous workspace to the same key

spaces

Basically I imagine it like this:
I am on workspace 5, I press "shortcut" and it moves me to set workspace number 8 (or something). When I am done, I press the same shortcut and it moves me to workspace 5 again.

Best Answer

System Preferences > Keyboard > Shortcuts sets keyboard shortcuts for all Desktops to CTRL n (where n is the number of the Desktop).

enter image description here

However, they are disabled by default. So it would be very easy to press CTRL 8 and CTRL 5 to switch between Desktops. If you wanted the same shortcut for both actions, you would have to use some kind of script to check the current Desktop setting and make the appropriate move.