<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>i3 FAQ - Individual question feed</title><link>https://faq.i3wm.org/questions/</link><description>Frequently asked questions and answers about the i3 window manager</description><atom:link href="http://faq.i3wm.org/feeds/question/3579/" rel="self"></atom:link><language>en</language><copyright>Copyright i3, 2012</copyright><lastBuildDate>Wed, 01 Oct 2014 01:04:45 +0000</lastBuildDate><item><title>auto sort workspace number</title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/</link><description>Hello,

I'm a very happy user of i3 but I have a question that I did not find any answer.

I want i3 to automatically sort the workspace number when I close one in a interval of 2 or more.

For example, I'm using workspace 1, 2, 3 and 4. I close all the windows on workspace 3. I now have workspace 1, 2 and 4 active.

What I want is workspace 1, 2 and 3. Workspace 4 can be renamed Workspace 3 or everything in workspace 4 is now in workspace 3.

How can I achieve that ?

Thank you very much !</description><pubDate>Thu, 27 Mar 2014 15:47:50 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/</guid></item><item><title>Answer by char_star for &lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I'm a very happy user of i3 but I have a question that I did not find any answer.&lt;/p&gt;

&lt;p&gt;I want i3 to automatically sort the workspace number when I close one in a interval of 2 or more.&lt;/p&gt;

&lt;p&gt;For example, I'm using workspace 1, 2, 3 and 4. I close all the windows on workspace 3. I now have workspace 1, 2 and 4 active.&lt;/p&gt;

&lt;p&gt;What I want is workspace 1, 2 and 3. Workspace 4 can be renamed Workspace 3 or everything in workspace 4 is now in workspace 3.&lt;/p&gt;

&lt;p&gt;How can I achieve that ?&lt;/p&gt;

&lt;p&gt;Thank you very much !&lt;/p&gt;
 </title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?answer=3601#post-id-3601</link><description>Okay, I just solved this problem for myself since the previous answerer's script doesn't seem to want to work for me. I used the golang i3ipc library.
You can find that library here: http://www(dot)github.com/proxypoke/i3ipc

I prefer to use the spelled out names for the workspaces, i.e. "one", "two", "three", etc., but you should change this in the script to whatever your preference is. It is as easy as modifying those strings in the nums[10] array. 
I am NOT much of a Go programmer, as I merely cobbled together enough of an understanding of the language to accomplish this feat. If someone would like to reply with a more idiomatic 'go-ified' version of my script, feel free.
Anyway, here's the script I made, called arrange_ws.go:

&lt;pre&gt;&lt;code&gt;
package main

import (
	"fmt"
	"sort"
	"github.com/proxypoke/i3ipc"
)
func main() {
	ipc, _  := i3ipc.GetIPCSocket()
	defer  ipc.Close()
	var nums [10]string
	nums[0] = "zero"
	nums[1] = "one"
	nums[2] = "two"
	nums[3] = "three"
	nums[4] = "four"
	nums[5] = "five"
	nums[6] = "six"
	nums[7] = "seven"
	nums[8] = "eight"
	nums[9] = "nine"
	ws_events, _ := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
	for {
		event := &lt;-ws_events
		if event.Change != "" {
			var wknums [10]int
			for i := range wknums {
				wknums[i] = 0xDEADBEEF
			}
			wkspcs, _ := ipc.GetWorkspaces()
			for i := range wkspcs {
				for j := range nums {
					if wkspcs[i].Name == nums[j] {
						wknums[i] = i
					}
				}
			}
			sort.Ints(wknums[0:9])
			for i := range wkspcs {
				if wkspcs[i].Name != nums[i]  {
						command := fmt.Sprintf("rename workspace %s to %s", wkspcs[i].Name, nums[i])
						fmt.Println(command)
						ipc.Command(command)
				}
			}
		}
	}
}
&lt;/code&gt;
&lt;/pre&gt;</description><pubDate>Tue, 01 Apr 2014 04:37:35 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?answer=3601#post-id-3601</guid></item><item><title>Comment by TonyC for &lt;p&gt;Okay, I just solved this problem for myself since the previous answerer's script doesn't seem to want to work for me. I used the golang i3ipc library.
You can find that library here: &lt;a href="http://www(dot)github.com/proxypoke/i3ipc"&gt;http://www(dot)github.com/proxypoke/i...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer to use the spelled out names for the workspaces, i.e. "one", "two", "three", etc., but you should change this in the script to whatever your preference is. It is as easy as modifying those strings in the nums[10] array. 
I am NOT much of a Go programmer, as I merely cobbled together enough of an understanding of the language to accomplish this feat. If someone would like to reply with a more idiomatic 'go-ified' version of my script, feel free.
Anyway, here's the script I made, called arrange_ws.go:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
package main

import (
    "fmt"
    "sort"
    "github.com/proxypoke/i3ipc"
)
func main() {
    ipc, _  := i3ipc.GetIPCSocket()
    defer  ipc.Close()
    var nums [10]string
    nums[0] = "zero"
    nums[1] = "one"
    nums[2] = "two"
    nums[3] = "three"
    nums[4] = "four"
    nums[5] = "five"
    nums[6] = "six"
    nums[7] = "seven"
    nums[8] = "eight"
    nums[9] = "nine"
    ws_events, _ := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
    for {
        event := &amp;lt;-ws_events
        if event.Change != "" {
            var wknums [10]int
            for i := range wknums {
                wknums[i] = 0xDEADBEEF
            }
            wkspcs, _ := ipc.GetWorkspaces()
            for i := range wkspcs {
                for j := range nums {
                    if wkspcs[i].Name == nums[j] {
                        wknums[i] = i
                    }
                }
            }
            sort.Ints(wknums[0:9])
            for i := range wkspcs {
                if wkspcs[i].Name != nums[i]  {
                        command := fmt.Sprintf("rename workspace %s to %s", wkspcs[i].Name, nums[i])
                        fmt.Println(command)
                        ipc.Command(command)
                }
            }
        }
    }
}
&lt;/code&gt;
&lt;/pre&gt;
</title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3609#comment-3609</link><description>It's a little tricky to install right now because it's a C library. Ideally someone would host a package for your distro.</description><pubDate>Tue, 01 Apr 2014 15:24:30 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3609#comment-3609</guid></item><item><title>Comment by char_star for &lt;p&gt;Okay, I just solved this problem for myself since the previous answerer's script doesn't seem to want to work for me. I used the golang i3ipc library.
You can find that library here: &lt;a href="http://www(dot)github.com/proxypoke/i3ipc"&gt;http://www(dot)github.com/proxypoke/i...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer to use the spelled out names for the workspaces, i.e. "one", "two", "three", etc., but you should change this in the script to whatever your preference is. It is as easy as modifying those strings in the nums[10] array. 
I am NOT much of a Go programmer, as I merely cobbled together enough of an understanding of the language to accomplish this feat. If someone would like to reply with a more idiomatic 'go-ified' version of my script, feel free.
Anyway, here's the script I made, called arrange_ws.go:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
package main

import (
    "fmt"
    "sort"
    "github.com/proxypoke/i3ipc"
)
func main() {
    ipc, _  := i3ipc.GetIPCSocket()
    defer  ipc.Close()
    var nums [10]string
    nums[0] = "zero"
    nums[1] = "one"
    nums[2] = "two"
    nums[3] = "three"
    nums[4] = "four"
    nums[5] = "five"
    nums[6] = "six"
    nums[7] = "seven"
    nums[8] = "eight"
    nums[9] = "nine"
    ws_events, _ := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
    for {
        event := &amp;lt;-ws_events
        if event.Change != "" {
            var wknums [10]int
            for i := range wknums {
                wknums[i] = 0xDEADBEEF
            }
            wkspcs, _ := ipc.GetWorkspaces()
            for i := range wkspcs {
                for j := range nums {
                    if wkspcs[i].Name == nums[j] {
                        wknums[i] = i
                    }
                }
            }
            sort.Ints(wknums[0:9])
            for i := range wkspcs {
                if wkspcs[i].Name != nums[i]  {
                        command := fmt.Sprintf("rename workspace %s to %s", wkspcs[i].Name, nums[i])
                        fmt.Println(command)
                        ipc.Command(command)
                }
            }
        }
    }
}
&lt;/code&gt;
&lt;/pre&gt;
</title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3608#comment-3608</link><description>I don't think it's actually a problem with the script per se, but after I installed all the dependencies, when I run the script, it complains about a missing Typelib file, and that causes me to be unable to import i3ipc. I'm not sure what the problem is because I am sure I have the dependencies...</description><pubDate>Tue, 01 Apr 2014 14:51:16 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3608#comment-3608</guid></item><item><title>Comment by TonyC for &lt;p&gt;Okay, I just solved this problem for myself since the previous answerer's script doesn't seem to want to work for me. I used the golang i3ipc library.
You can find that library here: &lt;a href="http://www(dot)github.com/proxypoke/i3ipc"&gt;http://www(dot)github.com/proxypoke/i...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer to use the spelled out names for the workspaces, i.e. "one", "two", "three", etc., but you should change this in the script to whatever your preference is. It is as easy as modifying those strings in the nums[10] array. 
I am NOT much of a Go programmer, as I merely cobbled together enough of an understanding of the language to accomplish this feat. If someone would like to reply with a more idiomatic 'go-ified' version of my script, feel free.
Anyway, here's the script I made, called arrange_ws.go:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
package main

import (
    "fmt"
    "sort"
    "github.com/proxypoke/i3ipc"
)
func main() {
    ipc, _  := i3ipc.GetIPCSocket()
    defer  ipc.Close()
    var nums [10]string
    nums[0] = "zero"
    nums[1] = "one"
    nums[2] = "two"
    nums[3] = "three"
    nums[4] = "four"
    nums[5] = "five"
    nums[6] = "six"
    nums[7] = "seven"
    nums[8] = "eight"
    nums[9] = "nine"
    ws_events, _ := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
    for {
        event := &amp;lt;-ws_events
        if event.Change != "" {
            var wknums [10]int
            for i := range wknums {
                wknums[i] = 0xDEADBEEF
            }
            wkspcs, _ := ipc.GetWorkspaces()
            for i := range wkspcs {
                for j := range nums {
                    if wkspcs[i].Name == nums[j] {
                        wknums[i] = i
                    }
                }
            }
            sort.Ints(wknums[0:9])
            for i := range wkspcs {
                if wkspcs[i].Name != nums[i]  {
                        command := fmt.Sprintf("rename workspace %s to %s", wkspcs[i].Name, nums[i])
                        fmt.Println(command)
                        ipc.Command(command)
                }
            }
        }
    }
}
&lt;/code&gt;
&lt;/pre&gt;
</title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3602#comment-3602</link><description>What was it about the other script that did not work for you?</description><pubDate>Tue, 01 Apr 2014 08:10:56 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=3602#comment-3602</guid></item><item><title>Comment by drosehill for &lt;p&gt;Okay, I just solved this problem for myself since the previous answerer's script doesn't seem to want to work for me. I used the golang i3ipc library.
You can find that library here: &lt;a href="http://www(dot)github.com/proxypoke/i3ipc"&gt;http://www(dot)github.com/proxypoke/i...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer to use the spelled out names for the workspaces, i.e. "one", "two", "three", etc., but you should change this in the script to whatever your preference is. It is as easy as modifying those strings in the nums[10] array. 
I am NOT much of a Go programmer, as I merely cobbled together enough of an understanding of the language to accomplish this feat. If someone would like to reply with a more idiomatic 'go-ified' version of my script, feel free.
Anyway, here's the script I made, called arrange_ws.go:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
package main

import (
    "fmt"
    "sort"
    "github.com/proxypoke/i3ipc"
)
func main() {
    ipc, _  := i3ipc.GetIPCSocket()
    defer  ipc.Close()
    var nums [10]string
    nums[0] = "zero"
    nums[1] = "one"
    nums[2] = "two"
    nums[3] = "three"
    nums[4] = "four"
    nums[5] = "five"
    nums[6] = "six"
    nums[7] = "seven"
    nums[8] = "eight"
    nums[9] = "nine"
    ws_events, _ := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
    for {
        event := &amp;lt;-ws_events
        if event.Change != "" {
            var wknums [10]int
            for i := range wknums {
                wknums[i] = 0xDEADBEEF
            }
            wkspcs, _ := ipc.GetWorkspaces()
            for i := range wkspcs {
                for j := range nums {
                    if wkspcs[i].Name == nums[j] {
                        wknums[i] = i
                    }
                }
            }
            sort.Ints(wknums[0:9])
            for i := range wkspcs {
                if wkspcs[i].Name != nums[i]  {
                        command := fmt.Sprintf("rename workspace %s to %s", wkspcs[i].Name, nums[i])
                        fmt.Println(command)
                        ipc.Command(command)
                }
            }
        }
    }
}
&lt;/code&gt;
&lt;/pre&gt;
</title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=4685#comment-4685</link><description>Excuse the dumb question, but where do you put/call this script for it to work?</description><pubDate>Wed, 01 Oct 2014 01:04:45 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?comment=4685#comment-4685</guid></item><item><title>Answer by TonyC for &lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I'm a very happy user of i3 but I have a question that I did not find any answer.&lt;/p&gt;

&lt;p&gt;I want i3 to automatically sort the workspace number when I close one in a interval of 2 or more.&lt;/p&gt;

&lt;p&gt;For example, I'm using workspace 1, 2, 3 and 4. I close all the windows on workspace 3. I now have workspace 1, 2 and 4 active.&lt;/p&gt;

&lt;p&gt;What I want is workspace 1, 2 and 3. Workspace 4 can be renamed Workspace 3 or everything in workspace 4 is now in workspace 3.&lt;/p&gt;

&lt;p&gt;How can I achieve that ?&lt;/p&gt;

&lt;p&gt;Thank you very much !&lt;/p&gt;
 </title><link>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?answer=3597#post-id-3597</link><description>You can do this with the new [ipc library](https://github.com/acrisci/i3ipc-glib). This script uses the [JavaScript](https://github.com/acrisci/i3ipc-gjs) version but the same API is available in many languages. You can find the latest version of this script [here](https://github.com/acrisci/i3ipc-gjs/blob/master/examples/auto-harmonious-ws-nums.js).
    
    #!/usr/bin/env gjs

    /*
       This example shows how to renumber your workspaces so they are consolidated
       into a harmonious linear order starting from 1 automatically when a
       workspace is closed. For instance, if you have open workspaces 1, 2, 4 they
       will be renumbered to 1, 2, 3 respectively when you move out of the
       workspace with no containers.

       https://faq.i3wm.org/question/3579/auto-sort-workspace-number/
    */

    const i3ipc = imports.gi.i3ipc;

    let conn = new i3ipc.Connection;

    conn.on('workspace::empty', function(conn, e) {
        let workspaces = conn.get_workspaces().filter(function(ws) {
            return !isNaN(parseInt(ws.name));
        }).sort(function(a, b) {
            return parseInt(a.name) - parseInt(b.name);
        });

        workspaces.forEach(function(ws, i) {
            let new_name = ws.name.replace(parseInt(ws.name).toString(), (i + 1).toString());
            conn.command('rename workspace "' + ws.name + '" to "' + new_name + '"');
        });
    });

    conn.main();
</description><pubDate>Sun, 30 Mar 2014 18:44:29 +0000</pubDate><guid>https://faq.i3wm.org/question/3579/auto-sort-workspace-number/?answer=3597#post-id-3597</guid></item></channel></rss>