Start up of an application on a specific desktop

I use a laptop for a jukebox with wireless speakers on my patio.

I use two desktops. My desktops are simply named ‘one’ and ‘two’. I have Strawberry Music player set to start up when I boot up. The OS (Ubuntu Mate 24.04) always boot so desktop ‘one’, and so does Strawberry.

Is there a way to get Strawberry to start on Desktop ‘two’ on startup instead of desktop ‘one’?

ps I have no idea on how to write a script

There is a command that can communicate with your windowmanager (marco)

sudo apt install wmctrl

From the commandline you can now switch to the 2nd workspace:

wmctrl -s1

(wmctrl starts to count at zero, so your first workspace is 0 , the second is 1, etc)

if you start strawberry now, it will start on the second workspace.

This is scriptable:

#!/bin/bash

wmctrl -s1
strawberry &
wmctrl -s0

You can add this script to 'autostart applications'

There are other solutions but none as simple as this one

7 Likes

... and, presumably, that would be included in an

  • rc.local

file.

:slight_smile:

1 Like

No, that wouldn't work. The script can only be started after the user logged in, X has started and following that, the windowmanager.
So it can only be called from a .desktop file in $HOME/.config/autostart/

The mate-control-center -> Startup Applications GUI will create this file automagically for you :slight_smile:

4 Likes

Thanks for the information.

1 Like

Please excuse my ignorance on this but here is what I did:

I installed sudo apt install wmctrl sucessfully.

then I used pluma to make a config file named <wmctrl -s1.config> and saved it in home>jim> .config

the files contains this:

#!/bin/bash

wmctrl -s1
strawberry &
wmctrl -s0

Strawberry did not start at all so I then went to system>preferences>personal>startup applications and made an entry for Strawberry and gave it a one second delay. It now starts but still on desktop one.

I am sure I am either missing something or don’t understand the instructions.

1 Like

Tricky name. Best practice is to avoid dashes and spaces, otherwise you have to be constantly alert to quote the name accurately.

A descriptive name would probably better, also to avoid mistakes and such.
You better rename it to strawberry_2nd_workspace.sh or something like that.

Also, a better place to store the script (conforming to convention) is in /home/jim/.local/bin
This has also the benefit of not needing the complete path to call it.

This command will take care of those things.

mv /home/jim/.config/'wmctrl -s1.config'  /home/jim/.local/bin/strawberry_2nd_workspace.sh 

Sorry, I forgot to mention that you have to make the script executable.
Use this:

chmod a+x  /home/jim/.local/bin/strawberry_2nd_workspace.sh

The autostart entry should be then strawberry_2nd_workspace.sh

That is to be expected. You need to call the script, not strawberry directly.
The script is not a configfile. It is an executable program, albeit very short :slight_smile:

By the way, you can test the script from terminal: strawberry_2nd_workspace.sh

3 Likes

Thanks, as I said I had no idea how to make a script, I will give these instructions a try.

2 Likes

I still can’t get it to work.

wmctrl successfully installed:

my Script:

Jim/.local didn’t have a bin folder so I created one by right clicking and saved the script in it.

I ran the chmod command:

I set Strawberry to open on startup.

I then saw the .config in the command so ran that. I deleted the .bin folder put the script on the desktop and ran the command.

mv /home/jim/.config/'wmctrl -s1.config' /home/jim/.local/bin/strawberry_2nd_workspace.sh

jim@g-laptop:~$ mv /home/jim/.config/'wmctrl -s1.config' /home/jim/.local/bin/strawberry_2nd_workspace.sh
mv: cannot stat '/home/jim/.config/wmctrl -s1.config': No such file or directory

I am confused one command says:

chmod a+x /home/jim/.local/bin/strawberry_2nd_workspace.sh and directs to .bin

the other command says:

mv /home/jim/.config/'wmctrl -s1.config' /home/jim/.local/bin/strawberry_2nd_workspace.sh and directs it to .config before directing it to .bin

.config strawberry has two files

one that looks like I created it today by the date.

I am pretty sure I can delete that as sudo without a problem.

Maybe I should just give the idea up?

Jim -

I did the following in my um24.04. My username is user
sudo apt install wmctrl strawberry
create a file, straw, in .local with contents wmctrl -s1; strawberry &
make that file exec, chmod +x /home/user/.local/straw

Went to Control Panel, Startup Apps, added "straw second window"

upon reboot, I saw strawberry in window 2

Hope it helps

3 Likes

No , just undo everything and follow the instructions of @pavlos_kairis.
That will work too.

(what went wrong is that you mixed up the order of the instructions...long story.
Anyway, if all else fails, i can write an automatic install for that, if you like)

1 Like

I made a file named straw and saved it to .local. It contained < wmctrl -s1; strawberry > I checked make executable and issued the command hmod +x /home/jim/.local/straw

I set startup applications to:

On reboot, Strawberry did start on desktop two(2), but the OS also booted into desktop two (2)!

I was hoping the desktop would boot in to desktop one (1) and Strawberry into desktop two (2).

So I am back to where I started.

Maybe this just isn’t possible? If that is the case I am okay with it, as it will start and play when I boot up, I just have to click on the one (1) desktop which is still easier.

Screenshot at 2025-10-29 14-14-57

Thanks tkn and Pavlos for all the help. I learned some things, but doubt I will ever be writing scripts myself.

1 Like

Edit your straw file and replace the contents with this:

#!/bin/bash

wmctrl -s1
strawberry &
wmctrl -s0
1 Like

That got be back to both opening on desktop one. I put it back to both opening on desktop two and just hitting the panel to get back to desktop one. That works for me so I will mark it solved.

1 Like

easy to fix ... the line becomes: wmctrl -s1; strawberry & ; wmctrl -s0

It reads: goto workspace 1 start strawberry in the background (&) and then go to workspace 0

2 Likes

wmctrl -s1; strawberry & ; wmctrl -s0

OS opened on desktop one (1) but strawberry failed to open. I named my desktops one and two and the OS shows one a 1 and two as 2 so I a guessing 0 is default for the OS to open (or my desktop one).

I tried putting the part of the command:

strawberry & ; wmctrl -s0

to strawberry & ; wmctrl -s2 but that made no difference either strawberry didn't

open so I put it back to Pavlov's first command.

I think that needs to be modified in the following manner to ensure the logical grouping encompasses the necessary states:

wmctrl -s1 ; strawberry & ; wait ; wmctrl -s0

No, for 'wmctrl' your desktop 'one' is '0' and your desktop 'two' is '1',
independent of how the user facing part of the OS is calling it.

1 Like

Sorry Eric but that put it back to opening on desktop two and strawberry not opening. I will just stick with Pavlos’ command. As long as strawberry opens on desktop two I am okay with going back to one for my main desktop. It might sound stupid but that is how I run all my other computers and to be different would be confusing at times.

2 Likes

Eric's command might work with a small modification:

wmctrl -s1 ; strawberry & ; sleep 0.2 ; wmctrl -s0

On my machine it worked without the sleep command, but my computer is relatively fast.

1 Like