How to sleep/pause during launcher command. [workaround found]

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
BenFenner
Level 1
Level 1
Posts: 31
Joined: Thu Feb 25, 2021 12:21 am

How to sleep/pause during launcher command. [workaround found]

Post by BenFenner »

I hope this is the right place to ask this.

I'm trying to launch an application using a launcher, but I'd like to delay the launch by some seconds.
You'd think it would be as easy as prepending a sleep command, but this is not working.

Here is an example command that should wait 2 seconds, then launch a terminal window but it doesn't work:
sleep 2s; mate-terminal

Any advice?

Image
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.
LM21.0 MATE
BenFenner
Level 1
Level 1
Posts: 31
Joined: Thu Feb 25, 2021 12:21 am

Re: How to sleep/pause during launcher command.

Post by BenFenner »

Well, I guess I could accomplish this a different way. I'm already running a command that loads an rcfile, so I guess I could add the sleep command to the rcfile as well.

Here is a simplified version of the actual command I'm using:
mate-terminal --command "bash --rcfile /home/bfenner/.bashrc_run_tests"

I'll just edit /home/bfenner/.bashrc_run_tests to add the sleep command there. Sorry for the trouble. It does seem odd I can't do what I was trying to do before.
LM21.0 MATE
1000
Level 5
Level 5
Posts: 999
Joined: Wed Jul 29, 2020 2:14 am

Re: How to sleep/pause during launcher command. [workaround found]

Post by 1000 »

1. To create a shortcut you can use only the executable file or command without special characters.
This is the reason why it did not work before and not will work.
More about "exec" in:
https://specifications.freedesktop.org/ ... 01s07.html

There you have all the specifications how the shortcut should be created and not only.

I don't know for what you need the delay.
But you can always build your own script

For example:

A) Create script own.mate.terminal in /usr/local/bin

Code: Select all

sudo xed /usr/local/bin/own.mate.terminal
For security you can use nano editor instead xed

Code: Select all

#!/bin/bash

sleep 2s ; /usr/bin/mate-terminal
B) Check and grant the appropriate permissions for /usr/local/bin/own.mate.terminal
Check

Code: Select all

$ ls -l /usr/local/bin/own.mate.terminal
-rw-r--r-- 1 root root 47 mar  2 14:32 /usr/local/bin/own.mate.terminal
Grant

Code: Select all

sudo chmod 755 /usr/local/bin/own.mate.terminal
Check again

Code: Select all

$ ls -l /usr/local/bin/own.mate.terminal
-rwxr-xr-x 1 root root 47 mar  2 14:32 /usr/local/bin/own.mate.terminal
C) Then try to create a shortcut for /usr/local/bin/own.mate.terminal

Code: Select all

[Desktop Entry]
Type=Application
Icon=terminal
Name=own.mate.terminal
Exec=/usr/local/bin/own.mate.terminal

================================{
A little explanation about greater possibilities:
- Usually you can install in
/opt or /usr/local/bin
More in https://refspecs.linuxfoundation.org/FH ... index.html

But,
I personally advise you
* single files install to /usr/local/bin
* large and complex projects to /opt
Because
- Default in Linux Mint, path /usr/local/bin exist in $PATH --> environmental variable in Linux

Code: Select all

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
path /opt not exist there.
For creating a shortcut it doesn't matter.
But it matters if you want to run the command ( own.mate.terminal ) without a complete path ( /usr/local/bin/ ).
If you will want install to /opt instead /usr/local/bin and you will want use short command own.mate.terminal.
Then you will need create symbolic link from /usr/bin/own.mate.terminal to /opt/own.mate.terminal

If we assume that /opt will for large projects then remember don't give /opt to $PATH.
For each binary file or script in /opt create a symbolic link. ( from /usr/bin/name to /opt/file_name )
Or create a directory only for single binary files or scripts then you can add this path to $PATH.
( Remember to create the appropriate permissions for files and folders )
================================}


About rcfile take into consideration that
- you probably replacing the original file
- mate-terminal works, but the window will pop up later
BenFenner
Level 1
Level 1
Posts: 31
Joined: Thu Feb 25, 2021 12:21 am

Re: How to sleep/pause during launcher command. [workaround found]

Post by BenFenner »

1000 wrote: Tue Mar 02, 2021 10:29 am About rcfile take into consideration that
- you probably replacing the original file
- mate-terminal works, but the window will pop up later
Don't worry, I'm sourcing the original file.
With the way I have things sourced and ordered, the terminal pops up, runs a few things, then sleeps, then runs the final command I am hoping for. It's quite nice. :)

Thanks for the tips about lib and opt. I took them to heart.
LM21.0 MATE
Locked

Return to “Scripts & Bash”