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/i...
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:
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 := <-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)
}
}
}
}
}