How to execute from desktop

Forum rules
Before you post please read this

How to execute from desktop

Postby ceauke on Wed Oct 12, 2011 7:22 am

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!
ceauke
Level 1
Level 1
 
Posts: 17
Joined: Wed Jul 06, 2011 8:32 am

Linux Mint is funded by ads and donations.
 

Re: How to execute from desktop

Postby xenopeek on Wed Oct 12, 2011 8:04 am

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).
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15054
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to execute from desktop

Postby ceauke on Wed Oct 12, 2011 8:16 am

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 :-)
ceauke
Level 1
Level 1
 
Posts: 17
Joined: Wed Jul 06, 2011 8:32 am

Re: How to execute from desktop

Postby xenopeek on Wed Oct 12, 2011 8:20 am

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.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15054
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to execute from desktop

Postby altair4 on Wed Oct 12, 2011 8:33 am

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.
altair4
Level 16
Level 16
 
Posts: 6152
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Postby xenopeek on Wed Oct 12, 2011 8:54 am

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.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15054
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to execute from desktop

Postby altair4 on Wed Oct 12, 2011 9:13 am

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.
altair4
Level 16
Level 16
 
Posts: 6152
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Postby xenopeek on Wed Oct 12, 2011 9:24 am

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.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15054
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How to execute from desktop

Postby altair4 on Wed Oct 12, 2011 10:07 am

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.
altair4
Level 16
Level 16
 
Posts: 6152
Joined: Tue Feb 03, 2009 10:27 am

Re: How to execute from desktop

Postby DrHu on Wed Oct 12, 2011 2:01 pm

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/
User avatar
DrHu
Level 16
Level 16
 
Posts: 6921
Joined: Wed Jun 17, 2009 8:20 pm

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 4 guests