Simplify opening a new application in a new workspace in i3-wm

We often use i3-msg to open applications in new workspaces. However to type all the name of our custom workspaces is tiresome. I created a simple (very simple) script to use just the number to specify the workspace and open the application in that workspace. This is a python script, which you can put inside a bin directory and execute it with the number of the workspace and the application you want to execute in that workspace. For this to work, change the custom workspace names that matches the names you have defined for your workspaces in i3. Save the following file as i3openit.sh.

#!/usr/bin/python

# i3openit.sh  
# E.g.
# i3openit.sh 5 firefox

import sys
import subprocess

if len(sys.argv) != 3:
    print("Usage: i3openit.sh <workspace-number> <program-name> ")
    sys.exit(0);

workspace = sys.argv[1];
program = sys.argv[2];

# Custom workspace names
if workspace == "1":
    workspace = "1:web";
if workspace == "2":
    workspace = "2:browse";
if workspace == "3":
    workspace = "3:reading";
if workspace == "4":
    workspace = "4:music";
if workspace == "5":
    workspace = "5:video";
if workspace == "6":
    workspace = "6:misc";
if workspace == "7":
    workspace = "7:files";

workspacefull = workspace + ';';

print ("Workspace: " + workspace, ", Program: ", program);
subprocess.call(["i3-msg", "workspace", workspacefull, "exec", program]);

Cheers !!

Leave a comment

Filed under Uncategorized

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s