I already have automatic tag assignation for clients using rules, but sometimes I need to spawn a client in a specific tag.

For example, I usualy want my browser (dwb) in tag 2 using the following rule:

awful.rules.rules = {
    { rule = { class = "Dwb" }, properties = { tag = tags[1][2] } },

But when spawning a browser for a debug session, I want it to spawn in another tag (along with my IDE) let's say tag 3.

How can I launch a program from the command line so that its client(s) will spawn in a tag specified as a parameter ?

1 Answer 1


You can create a function and use it through the awesome client tool.

First, create a function and add it to your rc.lua file :

function spawn(command, class, tag, test)
local test = test or "class"
local callback
callback = function(c)
    if test == "class" then
        if c.class == class then
            awful.client.movetotag(tag, c)
            client.disconnect_signal("manage", callback)
    elseif test == "instance" then
        if c.instance == class then
            awful.client.movetotag(tag, c)
            client.disconnect_signal("manage", callback)
    elseif test == "name" then
           if string.match(c.name, class) then
               awful.client.movetotag(tag, c)
            client.disconnect_signal("manage", callback)
client.connect_signal("manage", callback)

Then, restart your awesome session (generally through Ctrl+Super+r).

Then, as if you were writing a rule, choose the way to identify the client (window) to move. You can do it by class, by instance or by name. Use xprop to get informations on windows, also see this FAQ.

Finally, create a simple bash script :

#!/usr/bin/env bash
cat <<EOF | awesome-client
spawn("/usr/bin/firefox", "Firefox", tags[1][1], "class")

You can add as many spawn action you want. I have wrotten multiple startup scripts that launch all programs I need depending on the task I intend to work on.

Hope this helps.

  • Changing the callback is indeed quite a nice idea. I'll see if it solves my problem, especially for hard to identify clients and let you know
    – Preuk
    Jul 30, 2015 at 14:36
  • Very good solution, except for the client flashing on current screen; but that's not different from standard rules, thanks!
    – Preuk
    Jul 31, 2015 at 13:21
  • @mperrin: Thanks, I have an additional question: is it possible to differentiate between different instances of the same program? e.g. I would like different instances of google-chrome (with different profiles) to spawn on different tags. This method always matches the firs occurance (I think).
    – Emile 81
    Nov 1, 2017 at 21:16
  • Ok, after a bit of searching: the client also has a pid, so I could remember that somwhere and test against that, or if the client list is ordered (which it seems to be, I could just pass an index/offset/counter, so I keep matching until the (hopefully) right client instance is reached. Might post another answer if I get it to work.
    – Emile 81
    Nov 1, 2017 at 21:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .