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

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

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

Postby Linares » Nov 25th, '19, 21:57

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? :?:
Last edited by Linares on Nov 30th, '19, 13:50, edited 1 time in total.
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby magic » Nov 25th, '19, 22:52

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'
I see my C has been in the sea too long - it's gone rusty.
magic
 
Posts: 54
Joined: Jun 8th, '19, 09:38
Location: Nottinghamshire, UK

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

Postby Linares » Nov 25th, '19, 23:57

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
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby doktor5000 » Nov 26th, '19, 18:39

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
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18053
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

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

Postby Linares » Nov 26th, '19, 21:17

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*
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby doktor5000 » Nov 27th, '19, 18:17

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...'
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18053
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

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

Postby Linares » Nov 27th, '19, 23:29

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
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby doktor5000 » Nov 28th, '19, 13:51

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.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18053
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

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

Postby Linares » Nov 28th, '19, 19:25

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
Last edited by isadora on Nov 28th, '19, 20:50, edited 1 time in total.
Reason: Placed command-output in between [CODE]-tags for better readability ;)
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby JoesCat » Nov 29th, '19, 08:31

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).
User avatar
JoesCat
 
Posts: 177
Joined: Sep 15th, '11, 04:27
Location: Richmond, BC, Canada

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

Postby doktor5000 » Nov 29th, '19, 12:18

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.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18053
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

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

Postby JoesCat » Nov 29th, '19, 18:40

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.
User avatar
JoesCat
 
Posts: 177
Joined: Sep 15th, '11, 04:27
Location: Richmond, BC, Canada

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

Postby Linares » Nov 30th, '19, 03:42

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:
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby Linares » Nov 30th, '19, 12:23

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 4269 times


Thanks to all who have intervened with your ideas and contributions.
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby isadora » Nov 30th, '19, 12:27

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. :)
..........bird from paradise..........

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
—Antoine de Saint-Exupéry
User avatar
isadora
 
Posts: 2766
Joined: Mar 25th, '11, 16:03
Location: Netherlands

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

Postby Linares » Nov 30th, '19, 13:51

isadora wrote:Would you please mark this topic [SOLVED]?

Done. ;)
Linares
 
Posts: 145
Joined: Nov 25th, '19, 20:24
Location: Aizarna, Euskal Herria

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

Postby JoesCat » Nov 30th, '19, 22:30

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 ).
User avatar
JoesCat
 
Posts: 177
Joined: Sep 15th, '11, 04:27
Location: Richmond, BC, Canada


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest

cron