I am trying to write a bash script that needs some identifier of the current active desktop (I want my emacs-clients to connect to different servers depending on the active desktop). I have searched around and I can't seem to find a command that will get this information. Does such a thing exist?
I'm not sure exactly what you mean by "active desktop", but the command "system_profiler" can generate a vast amount of information about your computer. Between it's various settings and text filtering, you should be able to pluck out almost anything need to know.