Start up of an application on a specific desktop

Mine is relatively slow. It has an Intel(R) Core i5 cpu from 2009 that started life as a Win7 computer. That is why I use it as a jukebox. It is very slow until the graphics are built, after that it is relatively snappy. What ever I try to modify just keeps strawberry from opening, and I have given it plenty of time. Thanks again for the help.

1 Like

Not sure why the "wait" didn't work. It is supposed to ensure all background tasks are complete before allowing execution to proceed.

Anyone know why it didn't?

Also, for that sleep, I thought "bash" or "shell" required the number to be an integer?

Pavlos, do you know if that is only triggered on Reboot, or if it also triggered by a logout+login sequence?

That is correct, it is waiting for strawberry to close. :slight_smile:

2 Likes

Try to increase the sleeptime, like this:

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

if that works then you can decrease the sleeptime step by step to see what you can get away with :slight_smile:

1 Like

Startup Apps run after reboot. If you want to do something after login/logout, see

1 Like

@jymm I tried this script

#!/bin/sh

wmctrl -s1 ; firefox &        ; sleep 2
wmctrl -s2 ; gnome-terminal & ; sleep 2
wmctrl -s3 ; strawberry &     ; sleep 2
wmctrl -s0

after reboot
I see firefox on WS2, Terminal on WS3, strawberry on WS4, and it returns focus to WS1
(workspaces for humans are 1,2,3,4 but for the pc 0,1,2,3)

2 Likes

You are, of course, correct, Thom. Silly me!

1 Like

I will get back on it a bit later, have a busy weekend.

Strawberry is not starting on any ‘straw’ script at all now. I will delete everything, and give it a new name and run the command ‘chmod’ for the new name then.

2 Likes

Jymm
I wrote some notes, verified they work with um24.04
Seems I cannot upload a text file.
here's the termbin link, https://termbin.com/vf15

2 Likes

@jymm per @guiverc I post them as code:

# start strawberry in the background on workspace 2
# tested on um24.04  1 NOV 2025
# .................................................

Here are the steps I did today on um24.04

ls .config/autostart/ 

Control Panel | Startup Apps | Add

music
/home/user/music
music
2

Now, look again in ls .config/autostart, there is an entry, music.desktop

[Desktop Entry]
Type=Application
Exec=/home/user/music
Hidden=false
Name[en_US]=music
Name=music
Comment[en_US]=music
Comment=music
X-MATE-Autostart-Delay=2

Now, lets look at /home/user/music

#!/bin/sh
logger starting music
wmctrl -s1 ; strawberry & 
sleep 2
wmctrl -s0

the logger command will put a line in /var/log/syslog

chmod +x /home/user/music

reboot

pc starts: I see workspace 2 having strawberry and the focus is on workspace 1

if you grep music /var/log/syslog, there is an entry

2025-11-01T12:50:49.927349-07:00 um24 user: starting music


I hope this helps.
3 Likes

I will give that a try later today.

The reason that strawberry wouldn’t start on boot was I inadvertently deleted the start entry. Right now I have it back to starting on desktop 2

[Desktop Entry]
Type=Application
Exec=/home/user/music
Hidden=false
Name[en_US]=music
Name=music
Comment[en_US]=music
Comment=music
X-MATE-Autostart-Delay=2

I don’t see anything that tells it to open on desktop Two (1). It booted to desktop One(0) and Strawberry open on desktop One(0). I have the desktop entry set to 0 seconds and re-enabled the straw script you gave me to 1 second delay. Then it booted to desktop Two (1) and Strawberry opened on Desktop Two (I also tried disabling Strawberry under start up applications and then it doesn’t start at all on just the .config startup music.

Am I missing something?

Sorry, I don't understand the question.

The script says,
start strawberry on 1 (second rectangle),
sleep 2,
then go back to 0 (first rectangle).

I didn’t understand that. I will change it to that.

it was posted as code so you need to scroll down to see the script and the rest.

2 Likes

okay I didn’t know that. I also made a mistake I put music.desktop in startup applications as
/home/user/music
music
2

Instead of music
/home/jim/music
music
2

in start up apps.

Now, lets look at /home/user/music

#!/bin/sh
logger starting music
wmctrl -s1 ; strawberry & 
sleep 2
wmctrl -s0

does that mean I have to move the start up script from .local to music? \it in .local?

Do I still need a startup for strawberry in startup applications?

I will check back tomorrow, I am done for today. Thanks for all the help so far.

This may be a too-many-cooks-spoil-the-broth situation, but I thought I'd chime in.

Caveat: I'm not an expert.

Nevertheless, my experience is that when a script ends after being launched (for example, by the startup applications process), it propagates a SIGHUP signal to all (if any) of its child processes. What happens next depends on the app that was launched as a child process. The app may trap that signal and choose to ignore it, or it may use the default handling and terminate. This could be why @jymm wasn't seeing the strawberry app on desktop 2.

My takeway is this: If your script uses an ampersand to invoke an app in background mode, and you want that app to continue running after the script exits, you should invoke it with the nohup command to prevent the script's termination from propagating SIGHUP to the child process.

With that in mind, I wrote and tested the following script, and it worked on my 24.04 desktop, although I used engrampa as an example rather than strawberry, which I don't have installed.

#!/bin/bash

# Save the current desktop number.
current_desktop=$(xdotool get_desktop)

# Switch to the desired desktop.
xdotool set_desktop 1

# Give the desktop time to switch.
sleep 1

# Launch the app in the background; "nohup" allows the app to continue running
# when the script ends.
nohup engrampa &

# Allow time for the app to create its window on the desired desktop. (This  
# duration may need adjusting; it depends entirely on how quickly the app starts.)
sleep 1

# Restore the original desktop.
xdotool set_desktop "${current_desktop}"
3 Likes

Again excuse my ignorance but where do I put this file. In .local or .config? What is a proper name for this file? Will straw work of do I need a .suffix?

I have zero experience with code.

The script and its name can be anything.
eg. call this script play and place it in /home/jim/
If an extension was needed, we would write so.

cat /home/jim/play shows:

#!/bin/sh

current_desktop=$(xdotool get_desktop)

xdotool set_desktop 1
sleep 1
nohup thunderbird &
sleep 1

xdotool set_desktop "${current_desktop}"

Explanation: you have 4 workspaces on your screen, numbered 1,2,3,4. For the pc, those are identified as desktop 0,1,2,3. The script reads: save the current desktop, go to desktop 1, start an app with nohup and return to the desktop you started with.

You need to create a startup app from the Control Panel, it will appear as play.desktop

1 Like