6 <div id="content" class="usergen">
8 <h1>User-contributed article: Move a given workspace to active output</h1>
12 <p>Assume you have multiple monitors, and various workspaces on each of them.</p>
14 <p>You have some workspace 1 active on monitor A, and you want to jump to
15 workspace 2. The default behavior, using the built-in command <code>workspace 2</code>
16 is to display the workspace 2 on the screen it belongs to.</p>
18 <p>Another legitimate use-case would be to display the workspace 2 on the
19 currently active screen.</p>
21 <p>Unfortunately, there is no built-in command in i3 to achieve that, yet. However,
22 thanks to the IPC interface, it is possible to write an external script
27 <p>First, we need to create an executable script doing the job thanks to the <a href="/docs/ipc.html">IPC</a> interface.
28 In this article, we will assume the script is stored in <code>~/.config/i3/switch-workspace.py</code></p>
30 <p>Here is a possible implementation of the script:</p>
35 from json import loads
39 def ipc_query(req="command", msg=""):
40 ans = popen("i3-msg -t " + req + " " + msg).readlines()[0]
43 if __name__ == "__main__":
44 # Usage & checking args
46 print "Usage: switch-workspace.py name-of-workspace"
49 newworkspace = argv[1]
51 # Retrieving active display
53 for w in ipc_query(req="get_workspaces"):
55 active_display = w['output']
57 # Moving workspace to active display
58 print ipc_query(msg="'workspace " + newworkspace + "; move workspace to output " + active_display + "; workspace " + newworkspace + "'")
61 <p>This script uses i3-msg directly, but if you have several IPC scripts, or more
62 complex ones, or if you use quotes in your workspaces' names you may want to
63 use the <a href="https://github.com/ziberna/i3-py">python i3-ipc bindings</a>
64 as done in <a href="/docs/user-contributed/swapping-workspaces.html">this article</a>
65 (however, in this case, you might have to add some bindings to the library to
66 implement chained command since sequentiality is critical in this script).</p>
68 <p>Do not forget to make the script executable, usually, the following
69 command, assuming you adopted the naming of our article, should work:</p>
72 chmod u+x ~/.config/i3/switch-workspace.py
75 <h2>Configuration</h2>
77 <p>Once the script is created and made executable, the last step is to add the
78 corresponding bindings in your i3 conf file.</p>
80 <p>Basically, one way to do that is to replace the <code>workspace X</code> bindings with
81 <code>exec --no-startup-id ~/.config/i3/switch-workspace.py X</code>.</p>
83 <p>For a standard <em>fr bépo</em> keyboard layout, this will result in:</p>
87 bindsym $mod+quotedbl exec --no-startup-id ~/.config/i3/switch-workspace.py 1
88 bindsym $mod+guillemotleft exec --no-startup-id ~/.config/i3/switch-workspace.py 2
89 bindsym $mod+guillemotright exec --no-startup-id ~/.config/i3/switch-workspace.py 3
90 bindsym $mod+parenleft exec --no-startup-id ~/.config/i3/switch-workspace.py 4
91 bindsym $mod+parenright exec --no-startup-id ~/.config/i3/switch-workspace.py 5
92 bindsym $mod+at exec --no-startup-id ~/.config/i3/switch-workspace.py 6
93 bindsym $mod+plus exec --no-startup-id ~/.config/i3/switch-workspace.py 7
94 bindsym $mod+minus exec --no-startup-id ~/.config/i3/switch-workspace.py 8
95 bindsym $mod+slash exec --no-startup-id ~/.config/i3/switch-workspace.py 9
96 bindsym $mod+asterisk exec --no-startup-id ~/.config/i3/switch-workspace.py 10
99 <p>But of course, you will have to adapt this to your own keyboard layout.</p>
104 <li><a href="https://github.com/ziberna/i3-py">Python i3-ipc bindings</a></li>
105 <li><a href="/docs/user-contributed/swapping-workspaces.html">Swapping workspaces</a></li>
106 <li><a href="/docs/ipc.html">IPC interface</a></li>
107 <li>A bug repport explaining <a href="http://bugs.i3wm.org/report/ticket/809">how to make the focus follow the moved workspace</a></li>
110 <p>Author: <a href="http://captnfab.chezlefab.net/">captnfab</a>, 2014-08-02</p>