The i3 FAQ has migrated to All content here is read-only.
Ask Your Question

Open application and fix workspace

asked 2013-11-05 08:37:41 +0000

jr gravatar image

If i launch an application lets say on workspace1 and switch to another workspace before the application has started, the application launches on the new workspace. Instead i would like the app. to stay at workspace1 Is it somehow possible to fix this?

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted

answered 2013-11-05 09:48:31 +0000

Adaephon gravatar image

updated 2013-11-05 10:10:21 +0000

This already works, if you use

i3-msg exec application

to start your application it will appear on the workspace on which you called it. See here

For example, if you are using dmenu_run to start your application you can use this instead:

exe=`dmenu_path | dmenu ${1+"$@"}` && i3-msg "exec $exe"
edit flag offensive delete link more


does the behaviour of i3-msg exec application depends on the i3 version? the script runs but the behaviour is the same as the default setting edit: i compiled i3 from source and it works now but not with each programm. Is there a variable which contains the current worksp. so i can set it explict?

jr gravatar imagejr ( 2013-11-05 14:07:24 +0000 )edit

The User's guide and Flugsio mentioned that some apps that do not support this feature. You can retrieve the current workspace with `i3-msg -t get_workspaces`. This returns a list of all workspaces in JSON format. The current one has its "focused" flag set to true.

Adaephon gravatar imageAdaephon ( 2013-11-05 21:06:08 +0000 )edit

answered 2013-11-05 08:50:15 +0000

Flugsio gravatar image

updated 2013-11-05 11:10:47 +0000

Not at the moment, (edit) unless the application is startup-notification aware; see Adaephon's answer.

Although, you can pre-assign certain applications to workspaces

edit flag offensive delete link more



The part of the document you linked seems to be rather old (at least 2012 going by the ©) and the main focus is on cgroups not workspace awareness. I guess it did not get updated when the feature in question was introduced.

Adaephon gravatar imageAdaephon ( 2013-11-05 09:55:52 +0000 )edit

I had completely missed that feature. But there are some exception as the document says. chromium won't work with cgroups but might be fixable with startup-notification awareness. urxvt could be solved with either. Using exec for those doesn't work for me at the moment. i3 version 4.6 2013-08-07

Flugsio gravatar imageFlugsio ( 2013-11-05 11:25:40 +0000 )edit

answered 2014-02-07 15:38:09 +0000

I wrote a python script to implement this. So here is my config:

bindsym $mod+d exec /path/to/

And my script contains the following, apologies for the verbosity:

import subprocess
import json
from os.path import expanduser

def get_workspace():
  test = subprocess.Popen(["i3-msg","-t","get_workspaces"], stdout=subprocess.PIPE)
  output = test.communicate()[0]
  data = json.loads(output.decode())
  data = sorted(data, key=lambda k: k['name']) 
  for i in data:
      return i['name']

home = expanduser("~")
applications = open(home+"/.cache/dmenu_run")
dmenu_run = subprocess.Popen(["dmenu","-b"], stdout=subprocess.PIPE, stdin=applications)
output = (dmenu_run.communicate()[0]).decode().strip()
subprocess.Popen(["i3-msg","workspace "+get_workspace()+"; exec " + output], stdout=subprocess.PIPE)

The script simply:

  1. Pipes the current dmenurun cache (located at ~/.cache/dmenurun) of applications to dmenu
  2. Gets the result from dmenu and calls i3msg 'workspace <current>; exec <dmenu_result>' where current is the current workspace and dmenu_result is what you enter into the dmenu prompt
edit flag offensive delete link more

Question Tools


Asked: 2013-11-05 08:37:41 +0000

Seen: 891 times

Last updated: Feb 07 '14