2

I am trying to automate launching a few programs I use every time I do a particular activity. I generally launch these and then arrange them manually into different workspace.

I was wondering how to launch a program in a new workspace from the terminal, so that I could include this in a bash shell script.

I have wmctrl installed

1

quite simple actually using wmctrl and sleep. This is what I did:

#!/bin/bash

wmctrl -s 0                ############################################
                           # Switches to first workspace [workspaces are
                           # numbered from 0]
                           ############################################

firefox -private &         ############################################
                           # launches firefox in private mode in background
                           #
libreoffice --calc &       # launches libreoffice calc (alternative to MS
                           # Office Excel)
                           ############################################

sleep 10                   ############################################
                           # Application GUIs take some time to launch.
                           # Some more than others. We want to wait before
                           # running the next command) for some time before
                           # switching workspaces, so that it doesn't 
                           # switch before all applications we want in it
                           # have had enough time to launch. 
                           # N is in seconds. Try different values until
                           # you have figured out the right value for your
                           # system and set of applications
                           #############################################

wmctrl -s 1                # Switches to second workspace
evince ~/path/to/file.pdf &
sleep 1.5                  # evince is lightweight and the pdf file I am
                           # launching isn't that large either

wmctrl -s 2                # Switches to third workspace
mindmaster &
sleep 8

# and so on....

wmctrl -s 0 # Returns back to the first workspace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.