How to open a terminal and run a script by clicking on the icon
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
How to open a terminal and run a script by clicking on the icon
I've been trying to execute a bash script by clicking on the icon.
this script are in turn calling other scripts, and echoing status,and might request input if something happens.
but now when I'm clicking the link to the script, it asks if I want to run in terminal, display, cancel or run.
if I'm pressing run in a terminal, a terminal window pops up and closes immediately.
So my question is, how to keep the terminal window open until an "exit" command tells it to close, and if it's possible to make linux mint just run the script (when I'm clicking the link) without asking what to do?
this script are in turn calling other scripts, and echoing status,and might request input if something happens.
but now when I'm clicking the link to the script, it asks if I want to run in terminal, display, cancel or run.
if I'm pressing run in a terminal, a terminal window pops up and closes immediately.
So my question is, how to keep the terminal window open until an "exit" command tells it to close, and if it's possible to make linux mint just run the script (when I'm clicking the link) without asking what to do?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How to open a terminal and run a script by clicking on the icon
Open terminal.
There run script.
For example:
How use terminal, watch tutorials on youtube.
May I ask what kind it is your script? Can I see?
There run script.
For example:
Code: Select all
bash ./script_name
May I ask what kind it is your script? Can I see?
Re: How to open a terminal and run a script by clicking on the icon
How to run a script by clicking on an icon.
Here's a very easy way. Right click on your Desktop, and look for "Create a new launcher here...". If you have that option when you right click, you can easily select it and enter the required information to create a launcher.
Alternatively, here's another way that should work for nearly everyone:
1. Open a text editor with a new document.
2. Copy and paste the below into that new document. Change the "Name" and "Exec" settings to what is appropriate for the script that you want to execute. You can also change the "Icon" if desired. (If you want to call a script that outputs to the terminal, you'll want to add another line "Terminal=true" to the .desktop file below and maybe "read x" at the end of the script so you can stop the script before it closes.)
3. Save the file as example.desktop or other appropriate name in a good location, perhaps your desktop?
4. Change the permissions on this file to executable. Here's one way to do that:
In the directory where the .desktop file is located, open a terminal window. Then copy and paste this command into that window (change the name as appropriate and execute it, of course):
Now it should work when you double-click the "Example" icon (or whatever name you've selected.)
*** Credit goes to Linux Mint Forum user 1000 for the 2 methods above. ***
This will allow you to see the output before the window closes. Press 'Enter' to close the window.
Here's a very easy way. Right click on your Desktop, and look for "Create a new launcher here...". If you have that option when you right click, you can easily select it and enter the required information to create a launcher.
Alternatively, here's another way that should work for nearly everyone:
1. Open a text editor with a new document.
2. Copy and paste the below into that new document. Change the "Name" and "Exec" settings to what is appropriate for the script that you want to execute. You can also change the "Icon" if desired. (If you want to call a script that outputs to the terminal, you'll want to add another line "Terminal=true" to the .desktop file below and maybe "read x" at the end of the script so you can stop the script before it closes.)
Code: Select all
[Desktop Entry]
Version=1.0
Type=Application
Icon=mate-panel-launcher
Name=Example
Exec=xterm -hold -e "echo Hello My World"
4. Change the permissions on this file to executable. Here's one way to do that:
In the directory where the .desktop file is located, open a terminal window. Then copy and paste this command into that window (change the name as appropriate and execute it, of course):
Code: Select all
chmod +x example.desktop
*** Credit goes to Linux Mint Forum user 1000 for the 2 methods above. ***
I often add the following line to the end of my scripts:
Code: Select all
echo "Press Enter when complete."
read x
Last edited by Welcome on Wed Feb 17, 2021 11:56 am, edited 7 times in total.
Re: How to open a terminal and run a script by clicking on the icon
well, that's what I'm trying to avoid, I want to just click an icon and it should be done automatically.
Everybody knows how to do it via the terminal..
well, the script is parted into 4, where it scans the directory, determinate what it is, and acts accordingly..
Re: How to open a terminal and run a script by clicking on the icon
@wel
yes, it would work, but not here since there are several scripts being run, it looks like it starts one script and then closes the window, instead of showing the next scripts output
Re: How to open a terminal and run a script by clicking on the icon
Depends on how the other scripts are called. You can call the other scripts either synchronously or asynchronously.
If it was possible to call the other scripts synchronously, they'd run one-by-one in sequence.
You probably need them to run asynchronously. So, you'll need some method to 'signal' your main script when the other scripts are complete. Probably the easiest is to use a file to indicate that a script is complete. Or maybe even easier, an externally defined variable. There are some other methods of Inter Process Communication (IPC) such as named pipes, but their use in this case may be overkill.
If it was possible to call the other scripts synchronously, they'd run one-by-one in sequence.
You probably need them to run asynchronously. So, you'll need some method to 'signal' your main script when the other scripts are complete. Probably the easiest is to use a file to indicate that a script is complete. Or maybe even easier, an externally defined variable. There are some other methods of Inter Process Communication (IPC) such as named pipes, but their use in this case may be overkill.
Last edited by Welcome on Wed Feb 17, 2021 12:15 pm, edited 1 time in total.
Re: How to open a terminal and run a script by clicking on the icon
God idea, I bet the first script starts the other script so it runs in the background, I need to make it run after each other, so how do I start a script from a script so the first script waits for the second one..
Re: How to open a terminal and run a script by clicking on the icon
Are you expecting output from the other scripts to be displayed in the current window, AND you're calling them asychonously. There's a way to do that...
I've used the following style (runs in the current shell):I bet the first script starts the other script so it runs in the background, I need to make it run after each other, so how do I start a script from a script so the first script waits for the second one..
Code: Select all
. ./otherscript
Code: Select all
./otherscript
Edit: The dot-space is the same as the 'source' command. See 'help source' for more info.
Last edited by Welcome on Sun Feb 14, 2021 11:41 am, edited 3 times in total.
Re: How to open a terminal and run a script by clicking on the icon
For example, create two small script files test1 and test2.
In test1:
in test2:
Now, run test1 and you'll get this output:
Question: If you were running your scripts asychronously, did you use coproc? Or maybe as a background task? Or, could it be that a program called by your scripts is running asychronously?
In test1:
Code: Select all
variable1="Got me?"
echo In test1
. ./test2
echo Back in test1
Code: Select all
echo In test2....
echo $variable1
Now, try removing the dot-space and observe the output. See the difference?In test1
In test2....
Got me?
Back in test1
Question: If you were running your scripts asychronously, did you use coproc? Or maybe as a background task? Or, could it be that a program called by your scripts is running asychronously?
Last edited by Welcome on Wed Feb 17, 2021 11:18 am, edited 1 time in total.
Re: How to open a terminal and run a script by clicking on the icon
Could you post your scripts so that we can better help you? If not the full set of scripts, can you explain exactly what the scripts are attempting to accomplish? We'll be better able to help you if you provide that info. Thanks!
Last edited by Welcome on Wed Feb 17, 2021 11:27 am, edited 4 times in total.
Re: How to open a terminal and run a script by clicking on the icon
Code: Select all
. ./test2
But remember that relative path is not recommended. ( in finished products )
Try use absolute path ( . /path/to/test2 ) to file or more safe form relative path.
Edit
Code: Select all
xterm -hold -e "echo Hello My World"
Code: Select all
[Desktop Entry]
Version=1.0
Type=Application
Icon=mate-panel-launcher
Name=Example
Exec=xterm -hold -e "echo Hello My World"
Re: How to open a terminal and run a script by clicking on the icon
Thanks! This works great!1000 wrote: ⤴Sun Feb 14, 2021 12:41 pm Edit...Code: Select all
xterm -hold -e "echo Hello My World"
Last edited by Welcome on Wed Feb 17, 2021 11:24 am, edited 1 time in total.
Re: How to open a terminal and run a script by clicking on the icon
Even if your scripts are called sychronously from your main script, it also might be that the programs called in these many scripts run asychronously (that is, a program starts running and immediately returns control back to the script while it's still running). Some programs allow the user to select either "run asych" or "run sych", but most don't. If this is the case in your situation, you'll need to find some method of determining when the program completes, and test for it. Maybe the program will output a file when it's done. You'll need to test for the existance of this file, and you'll want to make sure the program has completed writting the output. You might be able to check the processes to see if the program is still running (or not). Of course, this would only work if it's the type of program that exits when it has completed it's task.
And, you might need to do this for every script/program that you've called.
Hard to help on this without knowing the details....
Re: How to open a terminal and run a script by clicking on the icon
Welcome wrote: ⤴Mon Feb 15, 2021 12:26 pmThanks! This works great!1000 wrote: ⤴Sun Feb 14, 2021 12:41 pm EditExample shortcut.desktopCode: Select all
xterm -hold -e "echo Hello My World"
Code: Select all
[Desktop Entry] Version=1.0 Type=Application Icon=mate-panel-launcher Name=Example Exec=xterm -hold -e "echo Hello My World"
This is a good way to make a "Launcher" in any desktop (Cinnamon, Mate, XFCE).
hello
i'm new and i dont get along with all the words and i need just one step by step tutorial on how (for exemple) make "xset dpms force off" run from desktop icon! i keep reading on the forum wich is great but some people dont use word .. like this you put there and other you put there ..... if you now what i mean and i get lost.... please if you can help me you would save me
tank you for your time even if you just read it
all the best
Re: How to open a terminal and run a script by clicking on the icon
I'm not an expert at this, but I'll try...tonicr33d wrote: ⤴Tue Feb 16, 2021 2:34 pm hello
i'm new and i dont get along with all the words and i need just one step by step tutorial on how (for exemple) make "xset dpms force off" run from desktop icon! i keep reading on the forum wich is great but some people dont use word .. like this you put there and other you put there ..... if you now what i mean and i get lost.... please if you can help me you would save me
tank you for your time even if you just read it
all the best
1. Open a text editor with a new document.
2. Copy and paste the below into that new document.
Code: Select all
[Desktop Entry]
Version=1.0
Type=Application
Icon=mate-panel-launcher
Name=Energy Star Off
Exec=xset dpms force off
4. Change the permissions on this file to executable. Here's one way to do that:
In the directory where the energystaroff.desktop file is located, open a terminal window. Then copy and paste this command into that window (and execute it, of course):
Code: Select all
chmod +x energystaroff.desktop
Did it work?
By the way, I see this was your first post to the forums! Welcome tonicr33d to the Linux Mint Forums!
Last edited by Welcome on Tue Feb 16, 2021 4:31 pm, edited 1 time in total.
Re: How to open a terminal and run a script by clicking on the icon
Because it is simple. Just click right mouse button on the desktop and then select the appropriate option and create the activator.
That's all.
If you have problem find option, you can create just file. (like above)
Also from terminal you can do.
For example, copy and paste to terminal ( then click Enter key ):
Allow the file to be opened as a program
And check how it works.
On YouTube you can find many tutorials, how to use the terminal.
That's all.
If you have problem find option, you can create just file. (like above)
Also from terminal you can do.
For example, copy and paste to terminal ( then click Enter key ):
Code: Select all
echo -e '[Desktop Entry]\nType=Application\nIcon=computer\nExec=xset dpms force off\nName=Turn off' > turnoff.desktop
Code: Select all
chmod +x turnoff.desktop
On YouTube you can find many tutorials, how to use the terminal.
Re: How to open a terminal and run a script by clicking on the icon
On the desktop is very important (in Cinnamon). When attempting to create a launcher in any directory window (including a Desktop window), a right click doesn't give the option to create the launcher. Only on the actual desktop.
Then, after the launcher is created, it can be moved to nearly any other useful directory.
Last edited by Welcome on Wed Feb 17, 2021 11:29 am, edited 1 time in total.
Re: How to open a terminal and run a script by clicking on the icon
well thank you for kindness, patience and worm welcome!
it works!!!!!
on cinnamon version i found like app down on panel where the volume is (for the same stuff) but on mate
( my machine is not that powerfull so i chose mate because of visuals in cinnamon. does that make sense??) .... can not find it
now i'll explore what else can i put in this way because copy and paste in terminal in not a option for me (not well organize)
Thank You and keep on helping!!!
it works!!!!!
on cinnamon version i found like app down on panel where the volume is (for the same stuff) but on mate
( my machine is not that powerfull so i chose mate because of visuals in cinnamon. does that make sense??) .... can not find it
now i'll explore what else can i put in this way because copy and paste in terminal in not a option for me (not well organize)
Thank You and keep on helping!!!