Page 1 of 1

[SOLVED] Script doesn't want to run when it's on KDE desktop

PostPosted: Nov 25th, '19, 21:57
by Linares
I have a simple script (#!/Bin/bash) that I run without problem opening a terminal. But I'm also interested in having it on the KDE desktop to run it with a double click. When I do, it simply does nothing. As if I didn't give it. :x

How can I also run it with a double click on KDE? :?:

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 25th, '19, 22:52
by magic
If you've got the script directly on the desktop I'd suggest moving it to somewhere else convenient (for example I have a directory ~/software with some bits and bobs in).
On the desktop right click and select 'Create New'>'Link to Application...'
A properties dialogue will open, give it a relevant name in the text box (and icon if you so choose).
Go to the 'Application' tab and enter the script details in the command box - or use the browse button to navigate to and select it.
If you want it to open in a window select 'Advanced Options' then select 'Run in terminal'

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 25th, '19, 23:57
by Linares
Hi.

I have performed the steps you indicated. But, when double clicking on the icon created on the desktop, the Konsole window opens to display the following message in red letters:

Warning: It was not possible to start «/home/and/aplicaciones/screenfetchmag.sh» with the arguments «/home/and/aplicaciones/screenfetchmag.sh».

Warning: execve: Incorrect executable format

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 26th, '19, 18:39
by doktor5000
Can you please post the contents of the .desktop file that was created by those steps ? And please also show the output, when you run the below command in a terminal
Code: Select all
ls -al /home/and/aplicaciones/screenfetchmag.sh

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 26th, '19, 21:17
by Linares
Of course.

The content of my simple scritp is:

Code: Select all
#!/bin/bash

magvariable=”MAG23/11/2019” 

echo $magvariable

screenfetch

read -rsp $'Pulsa ENTER para continuar\n'



And the output, when I run ./screenfetchmag.sh in a Konsole terminal is:

Code: Select all
”MAG23/11/2019”
               .°°.               and@localhost
                °°   .°°.         OS: Mageia 7 mga7
                .°°°. °°          Kernel: x86_64 Linux 5.3.11-desktop-1.mga7
                .   .             Uptime: 35m
                 °°° .°°°.        Packages: 2301
             .°°°.   '___'        Shell: bash
            .'___'        .       Resolution: 1920x1080
          :dkxc;'.  ..,cxkd;      DE: KDE 5.57.0 / Plasma 5.15.4
        .dkk. kkkkkkkkkk .kkd.    WM: KWin
       .dkk.  ';cloolc;.  .kkd    GTK Theme:  [GTK2/3]
       ckk.                .kk;   CPU: Intel Core i5-7400 @ 4x 3.5GHz [30.0°C]
       xO:                  cOd   GPU: EFI
       xO:                  lOd   RAM: 2908MiB / 7898MiB
       lOO.                .OO: 
       .k00.              .00x   
        .k00;            ;00O.   
         .lO0Kc;,,,,,,;c0KOc.   
            ;d00KKKKKK00d;       
               .,KKKK,.         
Pulsa ENTER para continuar



And the result of ls -al /home/and/aplicaciones/screenfetchmag.sh is:

Code: Select all
-rwxrwxr-x 1 and and 129 nov 26 20:13 screenfetchmag.sh*

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 27th, '19, 18:17
by doktor5000
I was not asking for the script, but the .desktop file that you created by in /home/username/Desktop by right click on the desktop and select 'Create New'>'Link to Application...'

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 27th, '19, 23:29
by Linares
Uops... Sorry for my mistake, due to my basic knowledge of English.

The .desktop file create in /home/and/Desktop by right click on the desktop and select 'Create New'>'Link to Application...' has this:

Code: Select all
[Desktop Entry]
Comment[es_ES]=M. A. G.
Comment=M. A. G.
Exec=/home/and/aplicaciones/screenfetchmag.sh
GenericName[es_ES]=Abre screenfetch en una ventana de terminal
GenericName=Abre screenfetch en una ventana de terminal
Icon=konsolekalendar
MimeType=
Name[es_ES]=Enlace a script screenfetch
Name=Enlace a script screenfetch
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=


Image

Image

Image

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 28th, '19, 13:51
by doktor5000
Sorry I can't reproduce your issue. Just created a script and a link to it as described here, and it runs just fine when launching it from the icon.

script

Code: Select all
[doktor5000@Mageia7VM ~]$ cat /home/doktor5000/script.sh
#!/bin/bash

echo this is a script

read -rsp "press ANY key" key

[doktor5000@Mageia7VM ~]$


.desktop file

Code: Select all
[doktor5000@Mageia7VM ~]$ cat ~/Desktop/link\ to\ script.desktop
[Desktop Entry]
Comment[en_US]=link to script
Comment=link to script
Exec=/home/doktor5000/script.sh
GenericName[en_US]=link to script
GenericName=link to script
Icon=exec
MimeType=
Name[en_US]=Link to Application
Name=Link to Application
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=
[doktor5000@Mageia7VM ~]$



Can you please check the MIME associations for shell scripts on your system? This is what it looks like here:

[doktor5000@Mageia7VM ~]$ xdg-mime query filetype ~/script.sh
application/x-shellscript
[doktor5000@Mageia7VM ~]$ xdg-mime query default application/x-shellscript
org.gnome.Builder.desktop
[doktor5000@Mageia7VM ~]$


In systemsettings5 > applications > file associations you can check what other applications can handle application/x-shellscript on your system.

Re: Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 28th, '19, 19:25
by Linares
Remembering the error:

https://photos.app.goo.gl/xHJBhAGeqGTowi3x8
Code: Select all
$ xdg-mime query filetype ~/aplicaciones/screenfetchmag.sh
application/x-shellscript

$ xdg-mime query default application/x-shellscript
org.kde.kwrite.desktop


Image

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 29th, '19, 08:31
by JoesCat
You need to do three things to make it work.
You already did one, which is you named the script ending in .sh

The second thing you need to do is make sure the file is visible to the user, so if the user is "boinc" then the file should be visible to the user "boinc" too. run ls -l and see if the user, group, other settings are set to allow this.

The third thing you need to do is indicate the script is "executable".
So it needs to at minimum be marked x for the user (and group, and other too if you put it in a shareable directory where others can use it too, but not needed for a private user desktop).
I have this setup for boinc.
Code: Select all
[boinc@home ~]$ ls -l boinc.sh
-rwxr-xr-- 1 boinc boinc 50 Aug 15  2016 boinc.sh*
[boinc@home ~]$ cat boinc.sh
#!/bin/sh
cd "/var/lib/boinc/" && exec boincmgr $@
[boinc@home ~]$


This is probably not important, since your default is probably set to bash, but some environments use sh.
For example cron jobs run at kernel level may likely be sh and not bash, so you may want to convert the bash to sh on your script.

edit: just saw "executable" on permissions, my error.
edit: try naming the desktop file something.sh instead of something.desktop (I recall having to do this on and older desktop).

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 29th, '19, 12:18
by doktor5000
JoesCat wrote:edit: try naming the desktop file something.sh instead of something.desktop (I recall having to do this on and older desktop).

That definitely won't help, a .desktop file is not executable that way. And file suffix doesn't mean anything, the kernel only looks at the shebang at the beginning of the file.
For shell scripts, you can easily leave of the .sh suffix, and as long as they're executable and have a valid shebang, they will run the same as without a suffix, this is just something artifical added for humans.

He just needs to adjust the MIME association to something that can actually execute shell scripts. You can e.g. associate it directly with bash for example.

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 29th, '19, 18:40
by JoesCat
You are right about the .desktop
I should have made a better example. Note, both examples have .sh as the end of the name because I noted it helped with an older KDE, so I just kept using the same method.
Code: Select all
[boinc@home ~]$ cp boinc.sh Desktop/boinc_1.sh
[boinc@home ~]$
[boinc@home ~]$ cd Desktop/
[boinc@home Desktop]$ ln -s ../boinc.sh boinc.sh
[boinc@home Desktop]$ ls -l
total 20
-rwxr-xr-- 1 boinc boinc   50 Nov 29 08:18 boinc_1.sh*
lrwxrwxrwx 1 boinc boinc   11 Nov 29 08:23 boinc.sh -> ../boinc.sh*
-rwxr-xr-x 1 boinc boinc 5932 Oct 20 15:52 org.kde.home.desktop*
-rw-r--r-- 1 boinc boinc 2902 Oct 20 15:52 org.kde.trash.desktop
-rwxr-xr-x 1 boinc boinc 2361 Oct 20 15:52 register.desktop*
[boinc@home Desktop]$

After creating them, both will appear on the Desktop, 1 is a file, and 2 is a link to ~/boinc.sh
You will also see the permissions are different.

because of using sh instead of bash, Linares example script may need to use:
sh screenfetch
and not
screenfetch

or else rename screenfetch as screenfetch.sh, add executable and call it as:
./screenfetch.sh
the ./ is to let the script know the file is in the local directory.

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 30th, '19, 03:42
by Linares
JoesCat wrote:You need to do three things to make it work.
You already did one, which is you named the script ending in .sh

The second thing you need to do is make sure the file is visible to the user, so if the user is "boinc" then the file should be visible to the user "boinc" too. run ls -l and see if the user, group, other settings are set to allow this.

The third thing you need to do is indicate the script is "executable".
So it needs to at minimum be marked x for the user (and group, and other too if you put it in a shareable directory where others can use it too, but not needed for a private user desktop).
I have this setup for boinc.
Code: Select all
[boinc@home ~]$ ls -l boinc.sh
-rwxr-xr-- 1 boinc boinc 50 Aug 15  2016 boinc.sh*
[boinc@home ~]$ cat boinc.sh
#!/bin/sh
cd "/var/lib/boinc/" && exec boincmgr $@
[boinc@home ~]$


This is probably not important, since your default is probably set to bash, but some environments use sh.
For example cron jobs run at kernel level may likely be sh and not bash, so you may want to convert the bash to sh on your script.

edit: just saw "executable" on permissions, my error.
edit: try naming the desktop file something.sh instead of something.desktop (I recall having to do this on and older desktop).


Hello.

Code: Select all
$ ls -l
-rwxrwxr-x  1 and and  129 nov 26 20:13 screenfetchmag.sh*


Image

As you can see, the .sh is executable.

And after rename .desktop to .sh, the script continues doing nothing:

https://photos.app.goo.gl/88JvdQh9vZzsEvEG8

:cry:

Re: Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 30th, '19, 12:23
by Linares
Problem solved. This little piece put me on the hint.

JoesCat wrote:
because of using sh instead of bash, Linares example script may need to use:
sh screenfetch
and not
screenfetch



In KDE, I edited the direct link to the script.
- Properties.
- Application.
- Order: sh /home/and/aplicaciones/screenfetchmag.sh

Now the bash script does in KDE what I was looking for.

script-ok.gif
script-ok.gif (454.38 KiB) Viewed 4272 times


Thanks to all who have intervened with your ideas and contributions.

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 30th, '19, 12:27
by isadora
Would you please mark this topic [SOLVED]?
You can do so by editing the title/subject of the first message in the topic.
Place [SOLVED] in front of subject/title.

Thanks ahead. :)

Re: Script doesn't want to run when it's on KDE desktop.

PostPosted: Nov 30th, '19, 13:51
by Linares
isadora wrote:Would you please mark this topic [SOLVED]?

Done. ;)

Re: [SOLVED] Script doesn't want to run when it's on KDE des

PostPosted: Nov 30th, '19, 22:30
by JoesCat
LOL - Glad it got resolved.
I started looking at this in more detail last night and realized my original suggestion wouldn't work because it opens a graphical program, while in your case you remain in bash and must see a terminal and interact with it, therefore you and the Doctor were correct in using the desktop link.

I copied your code and followed your steps and it ran 100%, so the doctor was correct nothing seemed functionally wrong here.
However, I was using Mageia6, 32bit (worked fine), and your example is Mageia7 64bit (needed sh helper here).

It appears like some sort of bug where sometimes the mimetype isn't identified, so KDE isn't sure what to do with the file and adding these extra hints like .sh or in your case "sh bashfile.sh" help (it has been around for a while - see step#6 here: http://www.joescat.com/boinc/#OPEN ).