i3-move-workspace-to-current-display 729 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. from json import loads
  3. from os import popen
  4. from sys import argv
  5. def ipc_query(req="command", msg=""):
  6. ans = popen("i3-msg -t " + req + " " + msg).readlines()[0]
  7. return loads(ans)
  8. if __name__ == "__main__":
  9. # Usage & checking args
  10. if len(argv) != 2:
  11. print("Usage: i3-switch-workspace name-of-workspace")
  12. exit(-1)
  13. newworkspace = argv[1]
  14. # Retrieving active display
  15. active_display = None
  16. for w in ipc_query(req="get_workspaces"):
  17. if w['focused']:
  18. active_display = w['output']
  19. # Moving workspace to active display
  20. print(ipc_query(msg="'workspace number " + newworkspace + "; move workspace to output " + active_display + "'"))