Is the sourcecode for the workspace utility online somewhere?
Besides that, you could try if the Workspaces applet can be asked for the currently active workspace with hey. I would have tried myself but I’m not on a Haiku machine right now.
You can get how many workspace there are from the settings message ${XDG_CONFIG_HOME}/system/app_server/workspaces
with a pinch of gawk you can do rows*columns to get it message ${XDG_CONFIG_HOME}/system/app_server/workspaces | awk 'BEGIN{i=1} /columns/,/rows/ {i=i*$(NF-1)} END{print i}' FS='[^0-9]'
I don’t know how to get the current workspace, perhaps with a trick, opening a new tracker window and getting its workspace with hey hey Tracker get Workspaces of Window $(hey Tracker count of Window | awk '/result/ {print $4-1}') | awk '/result/ {print 1+log($4)/log(2)}'