Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: How do you create an executable script to run from an icon?

  1. #1
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default How do you create an executable script to run from an icon?

    There are a few scripts I would like to be able to run from my desktop.

    An example is:
    Code:
    #! /bin/sh
    #
    # This script forces a full battery charge and keeps it charged above 95%
    #
    echo 95 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
    echo 100 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
    How do I create an icon on the KDE4 desktop that will run this script? I tried right clicking and choosing "link to application" but when I double click the icon it I just get the hour glass spinning for 30 secs. I've marked the script as executable. Anything else I need to do?
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

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

    Default Re: How do you create an executable script to run from an ic

    Code:
    #! /bin/sh
    should be
    Code:
    #!/bin/sh
    (no white space)

    You do not explain what you entered after choosing "link to application". How can we know if you made a mistake or not?

    Why double click? In my system that would start it twice!
    Henk van Velden

  3. #3

    Default Re: How do you create an executable script to run from an ic

    If you wanted to run it from your desktop say, I would plant a copy on the desktop, right click and then allocate an icon to it, in this case try and find one to do with a battery, you could also download a custom icon set of the internet to seperate the icon from the rest of your icons.

  4. #4
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default Re: How do you create an executable script to run from an ic

    Quote Originally Posted by hcvv View Post
    Code:
    #! /bin/sh
    should be
    Code:
    #!/bin/sh
    (no white space)

    You do not explain what you entered after choosing "link to application". How can we know if you made a mistake or not?

    Why double click? In my system that would start it twice!
    Thanks. White space removed now.

    You're right I should have listed what I was doing - sorry.

    General tab: I entered a name for the shortcut
    Permissions tab: Left as is.
    Application tab:
    >Name: Entered the same name as in general tab
    >Command: Browsed to the script.
    >Advanced options: Enabled feedback.

    I said double click as I'm from windows and everything there is double click. Old habits die hard.

    Quote Originally Posted by NismoTie
    If you wanted to run it from your desktop say, I would plant a copy on the desktop, right click and then allocate an icon to it, in this case try and find one to do with a battery, you could also download a custom icon set of the internet to separate the icon from the rest of your icons.
    I tried that but cannot change the icon. Right clicking and going to properties gives no option to change the icon.

    On thing, should the script filename have an extension or not or doesn't it matter?
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,153

    Default Re: How do you create an executable script to run from an ic

    On thing, should the script filename have an extension or not or doesn't it matter?
    Not needed. There is no such thing as an "extension" in Unix/Linux filenames. Some people call it so when a file name ends in a dot and a few other characters (and some programs draw conclusions from that), but is NOT a seperate field as in another OS.

    You say you browsed to the script. I hope the resulting string is an ABSOLUTE path to your script

    No further commentss on the double click (some people like it to wear out their fingers ).
    Henk van Velden

  6. #6
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default Re: How do you create an executable script to run from an ic

    I seem to have a problem with the script. It's not doing anything. I tried it as root too to make sure it was not a permission problem.

    The script is set to be executable so I'd expect clicking on it would execute it - right? When I try launch the script directly it looks like wine is trying to launch it.
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  7. #7
    Join Date
    Jun 2008
    Location
    /dev/belgium
    Posts
    1,946

    Default Re: How do you create an executable script to run from an ic

    Quote Originally Posted by hcvv View Post
    Code:
    #! /bin/sh
    should be
    Code:
    #!/bin/sh
    (no white space)
    this is not true, you can use either #! /bin/sh or #!/bin/sh ... both are valid

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,153

    Default Re: How do you create an executable script to run from an ic

    Quote Originally Posted by microchip8 View Post
    this is not true, you can use either #! /bin/sh or #!/bin/sh ... both are valid
    Hm, when you tested it you are most pobably correct. I always learned it without (on several Unixes and for more then 30 years now). In any case it is not his main problem.
    Henk van Velden

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,153

    Default Re: How do you create an executable script to run from an ic

    I never would think that you had not tested your scripts first, before trying to make it into a clickable thing. Test it from a console/terminal first!

    So first make your script working.

    BTW it should run as root, so just starting it from a user GUI won't work either. Your command inside the icon should be something like
    Code:
    su /path/to/the/script
    and you must be prepared to enter the root passwd, so I think it must be executed in a console/terminal to give you that change. Or use kdesu.
    Henk van Velden

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,153

    Default Re: How do you create an executable script to run from an ic

    Quote Originally Posted by microchip8 View Post
    this is not true, you can use either #! /bin/sh or #!/bin/sh ... both are valid
    Coming back on this. Wikipedia mentions "... then optionally any amount of whitespace ...". So it seems that you are right and I am ver old fashioned .
    Henk van Velden

Page 1 of 3 123 LastLast

Posting Permissions

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