What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

So, on a large display we use as a dashboard (of sorts) we have a few applications running - such as a 3D spacecraft position orbital viewer (similar to the one on this page).  We wanted to have several things running, and at timed intervals, switch between these applications (or views).  Specific use case was to show the orbital viewer for (say) 10 minutes, and then switch to showing something like feh to flip through some images for 10 minutes, and then switch back to the orbital viewer etc.

A simple approach to do this is to use native workspaces of your DM and a tool like xdotool in a script to switch between said workspaces.

After a few minutes, I came up with the following that works well (enough).

Guide

First you'll need to meet some requirements:

  • running some Linux distro with a window manager that has workspaces;
  • have xdotool  installed (for Arch based distros do: sudo pacman -S xdotool );
  • can run bash scripts (all distros should be able to do this);

The script

See below for the quick and dirty bash script.  Note this script simply alternates between workspace 1 and 2 (in that order) - you can change this if you want it to iterate over more than two workspaces (just change the numDesktops  variable).

#!/bin/bash 
 
# check have a delta argument
if [ -z "$1" ]; then
    echo "Please provide a number of seconds to switch desktops as first argument"
    exit 128
fi
 
if [ "$1" -lt 3 ]; then
    echo "Please provide a number of seconds >= 3"
    exit 128
fi
 
# init
numDesktops=2
desktop=$(xdotool get_desktop);
 
echo "Press Crtl+C or kill this script to stop the switching"
echo "Fist switch will occur in $1 seconds..."
while true 
do 
    sleep $1
    # change desktop
    desktop=$((desktop + 1))
    desktop=$((desktop % numDesktops))
    xdotool set_desktop $desktop
done

Copy / paste the script into a file using your preferred text editor and make it executable.  For example, I called my script switch-d.sh  so would do

chmod +x switch-d.sh

Now, just execute it with an argument (number of seconds to stay on a workspace before switching)

./switch-d.sh 600

and it should switch workspaces at that timed interval.

To stop it you'll need to either kill the process or wait until it switches to the workspace you have the terminal where you ran the script from and hit Ctrl+C .

Note if you use (an awesome) window manager like i3 where workspace don't exist until you have an open application/window on one - you'll need to make sure that something is open on a workspace for it to switch to it.