How to execute from desktop

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
ceauke

How to execute from desktop

Post by ceauke »

hi guys

I cant find the answer to this in the forums and I'm sure it's pretty easy. I created a very simple shell script as myfile.sh on the desktop. I marked it as executable and have a shebang line and a read line in it. However if you double click the file icon, it asks me if I want to execute the file or execute it in terminal. I can select either of the two but the terminal never opens.

Am I doing something wrong?

When I go to the terminal manually and ./myfile.sh then it executes fine.

I'm running linuxmintLXDE 11 in a VM

Thanks for help!
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.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: How to execute from desktop

Post by xenopeek »

LXDE can't run scripts or applications from the desktop. Even links aren't usable in LXDE. Pretty much the reason I've abandoned LXDE :roll:

Anyway, you can install lxshortcut package, that at least allows you to copy entries from the Menu as shortcut to the desktop. Anything else you need to run not from the desktop in LXDE.

For those running GNOME, following is a easy way to have the terminal appear and remain open until closed for your script:

Code: Select all

#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [ ! -t 0 ]; then
	gnome-terminal --command="bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
	exit
fi

# your code goes below
Just add it to the top of your script, and run it in future with "Run" instead of "Run in Terminal" and it will open its own terminal and remain open until you close it (allowing you to see output, which the "Run in Terminal" doesn't do).
Image
ceauke

Re: How to execute from desktop

Post by ceauke »

Thanks Vincent (Is jy Afrikaans?)

Any way to upgrade from LXDE to another version? I thought it was just a fast desktop without visual bells and whistles. Looks like they also cut the cojones off it :-)
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: How to execute from desktop

Post by xenopeek »

Nee, ik ben Nederlands :wink:

I don't know about easy upgrade from LXDE to GNOME. Probably you can add GNOME packages to the LXDE install, but that might not have the desired effect. Probably best just to backup your personal files, list of installed software, and reinstall (if that is what you want to do; LXDE really is a lot faster on anything with less than 1 or 2 GiB of memory at least). You could use mintBackup for that.
Image
altair4
Level 20
Level 20
Posts: 11458
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Post by altair4 »

I'm running Lubuntu 11.04 so maybe there's a difference with Mints LXDE offering but I can create a shortcut that opens a terminal , runs the command, and keeps the terminal open. Do I not understand the question?

Using lxshortcut:

Code: Select all

lxshortcut -o ~/Desktop/test.desktop
Command:

Code: Select all

lxterminal -e 'bash -c "ls -al;bash"'
Notice the extra pair of ' following the "-e".
It will run and keep the terminal open.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: How to execute from desktop

Post by xenopeek »

altair4 wrote:I'm running Lubuntu 11.04 so maybe there's a difference with Mints LXDE offering but I can create a shortcut that opens a terminal , runs the command, and keeps the terminal open. Do I not understand the question?
The question was why won't a "test.sh" script located on the desktop run if you double-click it on LXDE? It asks you how to execute, but then it doesn't do anything.
Image
altair4
Level 20
Level 20
Posts: 11458
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Post by altair4 »

I created a mini-script at /home/altair/test.sh and made it executable:

Code: Select all

#! /bin/bash
ls -al /etc/samba
Created a shortcut with the command:

Code: Select all

lxterminal -e 'bash -c "/home/altair/test.sh;bash"'
Double clicked it and got the following oputput:
total 44
drwxr-xr-x 2 root root 4096 2011-08-05 08:12 .
drwxr-xr-x 120 root root 4096 2011-10-12 08:27 ..
-rw-r--r-- 1 root root 8 2011-05-09 16:25 gdbcommands
-rw-r--r-- 1 root root 12582 2011-08-05 08:08 smb.conf
-rw-r--r-- 1 root root 12583 2011-08-05 08:08 smb.conf.ucf-dist
Does this not work?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: How to execute from desktop

Post by xenopeek »

altair4 wrote:Does this not work?
Yup, so thanks :D OP might want to use that perhaps.

The point remains, why can't you just make /home/altair/Desktop/test.sh and run it directly from there. That was what OP was trying.
Image
altair4
Level 20
Level 20
Posts: 11458
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Post by altair4 »

I'll admit that I'm way out of my comfort zone with all this but:

** I can't run that particular script in gnome either unless I create the equivalent Gnome shortcut:

Code: Select all

gnome-terminal -x bash -c "/home/altair/Desktop/test.sh; bash"
** But doesn't it depend on how the script was written?

For example, I can add your script ( modified ) to my command and it will execute in Lubuntu:

Code: Select all

#!/bin/bash

# if the script was not launched from a terminal, restart it from a terminal
if [ ! -t 0 ]; then
   lxterminal -e "bash -c \"$0 $*; read -s -p 'Press enter to continue...'\""
   exit
fi

# your code goes below
ls -al /etc/samba
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
DrHu

Re: How to execute from desktop

Post by DrHu »

Look at how an lxde menu item does run
--they use x-terminal-emulator to start a dialog

Same for other versions, look at how a terminal application starts
--if you can find one, since something may start with its own command rather than passing parameters to the GUI or terminal service..
--I might look at an application like MC (Midnight Commander) ore Gnome commander, which opens in a terminal using ncurses, but I think it also has a menu feature of execute a terminal program ?
http://en.wikipedia.org/wiki/Midnight_Commander
http://linux.die.net/man/1/mc
http://www.nongnu.org/gcmd/
Locked

Return to “Scripts & Bash”