i3wm : start applications on specific workspaces when i3 starts

  • How can I start applications on specific workspaces in i3 when it starts?

    Why is this not working in my config file? :

    workspace 1; exec firefox; workspace 2; exec chromium; workspace 1
    
  • jasonwryan

    jasonwryan Correct answer

    7 years ago

    According to the Arch Wiki i3 page, to autostart an application on a specific workspace, you use i3-msg:

    exec --no-startup-id i3-msg 'workspace 1:Web; exec /usr/bin/firefox'

    Yes, a line like `exec --no-startup-id i3-msg 'workspace 1; exec firefox; workspace 2; exec urxvt; workspace 1'` works. But, I find it a little odd to use `exec` on `i3-msg` which is a command meant to execute i3 commands. Why can't I directly write `workspace 1; exec firefox; workspace 2; exec urxvt; workspace 1` in my config file?

    This just opens everything in Workspace 1 for me.

    Works for most apps. However `google-chrome-stable` always opens on the last workspace in my setup. For example, with this configuration, Chrome opens on workspace 4 next to htop.

    Note that i3 now provides layout saving/restoring features that make it unnecessary to call i3-msg in most cases.

    @Wieland you should just edit that in to the answer...

    @danijar I would imagine it is because the amount of time it takes to startup Chrome exceeds the amount of time it takes to switch to workspace 4 and open urxvt. Google is smart and knows that the sooner it can get you a window the better, but they do this by returning "success" to the executing terminal/application (eg exec) ASAP and then loading the browser in a forked process, which is why exec thinks it was done with Chrome and it moved to the next line in your config. Add `&& sleep 3` and I'd bet Chrome opens in workspace 3. May need to go as high as 5 depending on # of extensions.

    @dragon788 I ended up opening all other applications first then switching to the workspace where I want chrome to show up. That way I don't introduce any unnecessary delay.

    @Wieland layout saving/restoring is different from auto start; the former only deals with setting up swallow traps for program windows while the latter starts an instance of an application as the OP requested.

    You might wish to update this answer. This formulation opens all applications in the same workspace, the one defined in the first `i3-msg` command in the config file. This might have functioned in older versions of i3, but seems no longer valid.

    I'm seeing the Chrome behavior described above affect Electron applications. This isn't surprising, but I thought it'd be worth mentioning for others finding their way here.

    For Chrome, I thought it wasn't respecting my workspace at first because it was going into a tab on the wrong workspace, where a Chrome instance was already open. (This was after i3 had fully loaded, not in my config.) Using `new-window` fixed it: `i3-msg 'workspace 2; exec google-chrome --new-window https://example.com'`

    how to place multiple windows in horizontal?

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM