title: Using hammerspoon and the spaces module to move window to new space
body: <p>I have installed the "undocumented spaces" module from <a href="https://github.com/asmagill/hs._asm.undocumented.spaces" rel="nofollow noreferrer">https://github.com/asmagill/hs._asm.undocumented.spaces</a>. In particular, it provides a method <code>moveWindowToSpace</code> that I am trying to use to bind <code>cmd+1</code> to move the the current window to space 1 using the following:</p>
  
  <pre><code>local spaces = require("hs._asm.undocumented.spaces")
  function MoveWindowToSpace(sp)
      local spaceID = spaces.query()[sp]
      spaces.moveWindowToSpace(hs.window.focusedWindow():id(), spaceID)
      spaces.changeToSpace(spaceID)
  end
  hs.hotkey.bind({"cmd"}, "1",function() MoveWindowToSpace(1) end)
  </code></pre>
  
  <p>This works in the sense that it moves the window to a new space, however, the spaces appear to be in a pseudo random order. </p>
  
  <p>Does any one know how to correctly map <code>spaceID</code>s, as returned by  <code>spaces.query()</code>, to the actual spaces?</p>