Re: [i3] About accessing workspaces by name

  • From: Kareem Khazem <karkhaz@xxxxxxxxx>
  • To: Discussions/Questions about the i3 window manager <i3-discuss@xxxxxxxxxxxxx>
  • Date: Tue, 16 Jun 2015 18:08:43 +0100

On 2015-06-16 1902, Nicolas Bercher wrote:

why and/or "switch to workspace by name" and "move window to
workspace by name" are not implemented?
(namely M-t <wpname> / M-S-t <wpname> under wmii.)

Hi Nicholas,

You can use i3-msg to do this from the command line. I use a
combination of i3-msg and dmenu to do this.

I wrote a script (ws_menu.rb) that finds the names of all workspaces
on DisplayPort-1, and lists them in dmenu, and when I type the name of
a workspace it switches to that one. If I type a name which is not
currently a workspace, then it creates a new workspace with that name
on DisplayPort-1.

You simply write this in your i3 config:
bindsym $mod+f exec /home/kareem/script/ws_menu.rb

And here is the script:

______________________________________________________________________
#!/usr/bin/env ruby

require 'json'

# Get workspaces on a particular output
workspaces = JSON.parse `i3-msg -t get_workspaces`
workspaces.select! {|ws| ws['output'] == "DisplayPort-1"}

# Build string of names
names = workspaces.map {|ws| ws['name']}
names = names.inject("") {|acc, e| e + "\n" + acc}

result = `echo "#{names}" | dmenu -p "Select Workspace:"`

if names.include? result
exec "i3-msg -t command workspace #{result}"
else
system "i3-msg -t command workspace new"
exec "i3-msg -t command rename workspace to #{result}"
end
______________________________________________________________________

Hope this helps

--
Kareem

Other related posts: