[Solved] What is the shell command to change workspace?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
sadhu
Level 5
Level 5
Posts: 862
Joined: Fri Nov 22, 2013 9:48 am
Location: Sri Lanka
Contact:

[Solved] What is the shell command to change workspace?

Post by sadhu »

I would like to write a simple shells script that would do the following

1. switch to workspace #N
2. run some app.[/list]

I can't seem to get xdotools to work, and in any case a script seems to be a more straightforward solution.

Back in the DOS days I had dozens of startup scripts (batch files), so this approach is nothing new.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
sabbe sattā bhavantu sukhitattā. LM 21.2-64 Cinn 5.8.4
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: What is the shell command to change workspace?

Post by xenopeek »

Try wmctrl instead. To switch to workspace N, you give the command `wmctrl -s N-1`. So to switch to your second workspace that would be:

Code: Select all

wmctrl -s 1
To switch back to your first workspace:

Code: Select all

wmctrl -s 0
You don't really need a script for this though. Say you are on the first workspace and want to switch to the second workspace and open Firefox there, the command to use would be:

Code: Select all

wmctrl -s 1 && firefox
If you want to use this as a launcher in your menu you need to change the command to be:

Code: Select all

bash -c "wmctrl -s 1 && firefox"
Image
User avatar
sadhu
Level 5
Level 5
Posts: 862
Joined: Fri Nov 22, 2013 9:48 am
Location: Sri Lanka
Contact:

Re: What is the shell command to change workspace?

Post by sadhu »

Works beautifully!
TYVM
sabbe sattā bhavantu sukhitattā. LM 21.2-64 Cinn 5.8.4
ericramos1990

Re: [Solved] What is the shell command to change workspace?

Post by ericramos1990 »

In case you wanted the xdotool solution, I use

Code: Select all

xdotool set_desktop 0
0 being the first workspace.

I only use 2 workspaces, so I made a script that toggles between both :)

Code: Select all

#!/bin/bash
aplay ~/notifications/workspace.wav &
if [ $(xdotool get_desktop) = 1 ]
then
xdotool set_desktop 0
else
xdotool set_desktop 1
fi
The first line is the sound effect from Cinnamon to switch workspaces you can find here:
/usr/share/mint-artwork-cinnamon/sounds/switch.oga

I had to convert it to .wav for aplay to play though
Locked

Return to “Scripts & Bash”