Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Clicking shell scripts in Dolphin doesn't cause them to open in a console

  1. #1
    Join Date
    Jan 2009
    Location
    Romania, Bucharest
    Posts
    789

    Default Clicking shell scripts in Dolphin doesn't cause them to open in a console

    I'm not sure if this is an issue or just how things work in KDE. But I am unable to run shell scripts properly by simply clicking them in Dolphin. Namely to get them opening in a new console... I think they run but in the background. In order to see what's happening, I need to right-click in an empty space, go to Actions, select Open Terminal here, then do "./myscript.sh" there instead.

    What I tried was to right-click a .sh file, go to Open With -> Other... and check "Run in terminal" and "Remember application association for this type of file", then selecting "bash" and clicking OK. Sadly, remembering application association does not include the running in a terminal part, so when I click the sh script it still runs in the background. How do I fix this?
    openSUSE Tumbleweed x64, KDE Framework 5

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,245

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to open in a console

    Quote Originally Posted by MirceaKitsune View Post
    .... But I am unable to run shell scripts properly by simply clicking them in Dolphin. Namely to get them opening in a new console...
    IMHO your idea bout what is "properly" is incorrect. You are mixing up two different things.

    1.
    When you "click" on a filename in Dolphin and that is the name of an executable, Dolphin will ask the Kernel to start a new process with that file. This is true whatever the nature of the executable: a binary created by compiling/linking a C or Fortan program or a script of any kind. Start Dolphin and travel to /usr/bin. There are many executables there. Take an innocent one, scroll down to xclock, click on it. The program xclock will now start. No terminal emulation will be started first. And IMHO this is what most people (excepting you) would expect

    2.
    In a desktop environment, you can have a list of associations to couple data files of a certain type to certain applications. This is not done by checking the contents of such data files, but by the convention of letting their file names end in certain character combinations. E.g. file names ending in .jpeg can be associated with the program /usr/bin/gwenview. For KDE and Dolphin this means that when you click on a file name some.jpeg, Dolphin will ask the Kernel to start a new process with the program /usr/bin/gwenview and with some.jpg as argument. This is the same one could let do a shell do by typing
    Code:
    /usr/bin/gwenview some.jpeg
    Now I am not sure, but my guess is that Dolphin first does check if the file name "clicked" is executable and when yes, never reaches 2. above.

    Even when it reaches 2. above, this would require an association between a file name ending (it seems that you prefer .sh for your case(s)) and a program. The program in your case should be a terminal emulator (you did not mention which one you prefer). There is something that that terminal emulation must be able to do: use the argument as if it was typed in preceded by a ./ combination in the emulator window. Neither konsole, nor xterm does this.
    Henk van Velden

  3. #3
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to openin a console

    On 2012-12-05 15:46, hcvv wrote:
    > Even when it reaches 2. above, this would require an association
    > between a file name ending (it seems that you prefer -.sh- for your
    > case(s)) and a program. The program in your case should be a terminal
    > emulator (you did not mention which one you prefer). There is something
    > that that terminal emulation *must* be able to do: use the argument as
    > if it was typed in preceded by a -./- combination in the emulator
    > window. Neither -konsole, -nor -xterm- does this.


    You could launch "xterm -e command [arguments]" instead of directly
    launching the script. There are more options in the manual.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.1 x86_64 "Asparagus" at Telcontar)

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,245

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to openin a console

    Quote Originally Posted by robin_listas View Post
    On 2012-12-05 15:46, hcvv wrote:
    > Even when it reaches 2. above, this would require an association
    > between a file name ending (it seems that you prefer -.sh- for your
    > case(s)) and a program. The program in your case should be a terminal
    > emulator (you did not mention which one you prefer). There is something
    > that that terminal emulation *must* be able to do: use the argument as
    > if it was typed in preceded by a -./- combination in the emulator
    > window. Neither -konsole, -nor -xterm- does this.


    You could launch "xterm -e command [arguments]" instead of directly
    launching the script. There are more options in the manual.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.1 x86_64 "Asparagus" at Telcontar)
    You mean by adding the -e in the manage application subwindow of the appropriate application in the list of applications associated with a pattern in the file assosiations in Configure desktop in KDE?

    Could work. But it could equaly break other things I think this is a case of asking about the symptom instead of explaining the real question. Either you create a program that runs in the CLI interactively and then you run it from the CLI, or you create a GUI program (interractive by design), or you create a stand-alone program.
    Henk van Velden

  5. #5
    Join Date
    Aug 2008
    Location
    Brazil
    Posts
    2,937

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to open in a console

    Just a thought: in KDE file associations, you can set an executable extension to open in a terminal. If you define a special extension under the same class as an executable and set it to open in a terminal. it might work. Or not.

  6. #6
    Join Date
    Jan 2009
    Location
    Romania, Bucharest
    Posts
    789

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to open in a console

    hcvv: That clarifies a lot. I didn't know that for executables it's a different "regime" when clicking them. I was expecting I could eg: Associate .sh with bash so it would open in a new console when clicked. For compiled binaries I prefer that they work this way (no console, just the program starting up).

    But yes... my wish was that clicking a sh file would launch it in a new bash instance rather than in the background. Since unlike binaries, I am interested in seeing the output of shell scripts usually. But if it's not possible I don't wish to hack into things and force the system beyond what it can do. I can live with manually opening a console and writing ./myscript.sh to run it. Though it would be nice if Dolphin added a setting whether to launch programs in a visible console or not.
    openSUSE Tumbleweed x64, KDE Framework 5

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,245

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to open in a console

    I hope you understand that it is not only different, but that it should be different. That is when one wants the feature that Dolphin starts a program when clicking on it (but what else would one want?). A script (bash, sh, csk, ksh, python, ruby) together with it's interpreter is an executable program like any other.
    None of them needs a terminal to be run from. But all can be run from a terminal with a running shell.

    And even when you associate a file name ending in .sh with the application bash (which is easily possible), that application would be run unattached from any terminal.

    It is btw completely useless to do so. Not only because Dolphin will start the executable without looking to a pattern in it's name, but also because the script starts with
    Code:
    #!/bin/bash
    end it is for this that the Kernel will load /usr/bin/bash to interprete the script (thus bash it is there by implication).
    Thus when you click with Dolphin, it will ask the Kernel to execute it. The Kernel will check the file end see in it's first line (looking for "the magic number") that /bin/bash should be loaded and started instead and that the script is to be offered as an argument to that process. Nowhere in this a terminal is needed, wanted or involved.
    Henk van Velden

  8. #8
    Join Date
    Jan 2009
    Location
    Romania, Bucharest
    Posts
    789

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to open in a console

    That pretty much sounds like it's not possible then... which is ok. Still, when you right-click the file and choose "Open With -> Other..." then check "Run in terminal", it does what I intend it to. So it seems like there is a way to pull it off, if you could only assign left-clicking to do that automatically. But it's probably a feature Dolphin won't have or need and I can live with manually running scripts from bash when I need to see output.

    I wonder if I can at least add a line to custom shell scripts to always make them open in a new terminal. Anyone know if that's possible instead?
    openSUSE Tumbleweed x64, KDE Framework 5

  9. #9
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to openin a console

    On 2012-12-05 17:46, hcvv wrote:
    > You mean by adding the -e in the manage application subwindow of the
    > appropriate application in the list of applications associated with a
    > pattern in the file assosiations in Configure desktop in KDE?


    I'm not familiar with doing this type of things in GUIs: me, I open a
    terminal in the appropriate directory and then start up the script. But
    I'm thinking that instead of associating a extension with bash, it could
    be associated with xterm and a certain combination of options and
    parameters. I don't know how exactly to do it O:-)

    Or maybe modify the shebang to something equivalent, if that is possible.


    However, if dolphin can be convinced to remember that it should open a
    terminal with scripts ending in a certain extension, that would be perfect.


    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.1 x86_64 "Asparagus" at Telcontar)

  10. #10
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: Clicking shell scripts in Dolphin doesn't cause them to openin a console

    On 2012-12-05 23:06, MirceaKitsune wrote:
    > I wonder if I can at least add a line to custom shell scripts to always
    > make them open in a new terminal. Anyone know if that's possible
    > instead?


    Play with the shebang.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 12.1 x86_64 "Asparagus" at Telcontar)

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •