Quick and dirty bash script to switch workspaces at timed intervals
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).
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
.