The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

Dynamically change workspace name with ease

asked 2012-09-09 07:13:54 +0000

Azrathud gravatar image

updated 2012-09-22 04:55:02 +0000

I want to change workspace names dynamically(rename workspaces without touching config files), and I have a script to do so(see this blog post). can execute this script through dmenu_run with a name as an argument to change the current workspace name, but I woulud rather not type in the name of the script. (Dmenu, not dmenu_run allows for graphical input conversion to stdout.)

Is there anyway I can 'inject' text (the script name and a space) into dmenu_run and have it open waiting for input, or is there a better way to dynamically change workspace names?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2012-09-22 04:48:54 +0000

Azrathud gravatar image

updated 2012-09-22 21:52:54 +0000

Okay, so I have created a solution.

First download workspace.rb(taken from the blog, Userbound). You will need ruby to run this script.


workspace.rb

#!/usr/bin/ruby
    require 'json'
    JSON.parse(%x[i3-msg -t get_workspaces]).each do |workspace|
            if (workspace['focused']) then
                    number = workspace['name'].split(/:/)[0]
                    newName = "#{number}: #{ARGV[0].chomp}"
                    %x[i3-msg 'rename workspace "#{workspace['name']}" to "#{newName}"']
                    %x[i3-msg 'bindsym Mod4+#{number} workspace "#{newName}"']
            end
    end

All it does is read from i3 and send messages to i3, so it can rename a workspace.

Then, download my script.


rename.sh

#!/bin/bash
# Rename current workspace

# deafult name and imput
name=$(echo -e "workspace" | dmenu)

ruby $HOME/scripts/wm-scripts/i3scripts/workspace.rb "$name"

It gets input gained from dmenu(with a default of 'workspace'), and then supplies that input into the ruby script.

Make sure you change the line ... $HOME/scripts/wm-scripts/i3scripts/workspace.rb ... to point to wherever you have saved workspace.rb

Now, go into your .i3 config and bind the script to a key in i3, and then reload your config(there is a shortcut for this reload by in the default config).


.i3/config

#rename workspace
bindsym Mod4+Shift+v exec /home/azrathud/scripts/wm-scripts/i3scripts/rename.sh

There you have dynamic workspace naming.

Note: see joepd's post about possible i3 workspace binding issues.

This behavior was weird. Apparently when I named my workspaces number 1, etc. I could rename them using i3-msg bindkey ..., but then other functions of i3 stopped working. Sorry for the confusion. Apparently shortcuts cannot be rebinded at runtime.

edit flag offensive delete link more

Comments

The `i3-msg bindsym …` does not actually work.

Michael gravatar imageMichael ( 2012-09-22 10:49:08 +0000 )edit

See above. I tried to find a workaround, but to no avail.

Azrathud gravatar imageAzrathud ( 2012-09-22 21:53:26 +0000 )edit
0

answered 2012-09-09 08:34:23 +0000

joepd gravatar image

I am not sure if I understand your question correctly, but aren't you confusing dmenu with dmenu_run? If so, running

less $(which dmenu_run)

will clear out any confusion.

As for your question, this probably is what you are looking for:

#!/bin/sh
result=$(cat FileWithNewlineSeparatedItems | dmenu)
yourscript "${result}"
edit flag offensive delete link more

Comments

I was confusing dmenu_run with dmenu. So here's what I have so far: ./i3/config ... bindsym Mod4+Shift+n exec /home/azrathud/.i3/rename.sh ... rename.sh #!/bin/bash # Rename current workspace # deafult name and imput name=$(echo -e "workspace" | dmenu) ruby $HOME/.i3/workspace.rb "$name" workspace.rb #!/usr/bin/ruby require 'json' JSON.parse(%x[i3-msg -t get_workspaces]).each do |workspace| if (workspace['focused']) then number = workspace['name'].split(/:/)[0] newName = "#{number}: #{ARGV[0].chomp}" %x[i3-msg 'rename workspace "#{workspace['name']}" to "#{newName}"'] %x[i3-msg 'bindsym Mod4+#{number} workspace "#{newName}"'] end end My problem now is that when I do modify the workspace name, I cannot use the Mod+{0-9} shortcuts to go back to it, only by clicking.

Azrathud gravatar imageAzrathud ( 2012-09-17 04:27:45 +0000 )edit

I suspect you have your bindsyms setup wrong, ie referring to the workspace name in stead of the workspace number. This works for me: i3-msg 'rename workspace "7: mail" to "7: email"' i3-msg 'workspace number 7'

joepd gravatar imagejoepd ( 2012-09-18 12:12:04 +0000 )edit

That did it. Thank you for all the help. My config was like: ... # switch to workspace bindsym Mod4+1 workspace 1 ... and so I changed it to ... # switch to workspace bindsym Mod4+1 workspace number 1 ... I'm going to post the final solution.

Azrathud gravatar imageAzrathud ( 2012-09-22 04:07:31 +0000 )edit

Question Tools

2 followers

Stats

Asked: 2012-09-09 07:13:54 +0000

Seen: 2,690 times

Last updated: Jun 14 '14