Skip to content

Instantly share code, notes, and snippets.

@97-109-107
Created February 3, 2015 13:28
Show Gist options
  • Save 97-109-107/b70356670ae8309ffb4f to your computer and use it in GitHub Desktop.
Save 97-109-107/b70356670ae8309ffb4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import i3
outputs = i3.get_outputs()
workspaces = i3.get_workspaces()
# figure out what is on, and what is currently on your screen.
workspace = list(filter(lambda s: s['focused']==True, workspaces))
output = list(filter(lambda s: s['active']==True, outputs))
# figure out the other workspace name
other_workspace = list(filter(lambda s: s['name']!=workspace[0]['output'], output))
# send current to the no-active one
i3.command('move', 'workspace to output '+other_workspace[0]['name'])
@kim366
Copy link

kim366 commented Oct 12, 2018

Ey, good thing I starred this! I just lost my i3 config and I just now get to appreciate the impact of this script on my workflow that I don't have it anymore!

@donovan
Copy link

donovan commented Jun 15, 2022

Thanks for this, works well. I modified the original to have clearer variable names, debug output and to use list comprehensions.

My version:

#!/usr/bin/env python3

import i3
import rich

DEBUG = False

outputs = i3.get_outputs()
workspaces = i3.get_workspaces()

focused_workspace = [w for w in workspaces if w["focused"] == True][0]
active_outputs = [o for o in outputs if o["active"] == True]
other_output = [o for o in active_outputs if o["name"] != focused_workspace["output"]][
    0
]

if DEBUG:
    print("outputs:")
    rich.print(outputs)
    print("workspaces:")
    rich.print(workspaces)
    print("focused_workspace:")
    rich.print(focused_workspace)
    print("active_outputs:")
    rich.print(active_outputs)
    print("other_workspace:")
    rich.print(other_output)

# Send current workspace to other output
i3.command("move", "workspace to output " + other_output["name"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment