Announcement

Collapse
No announcement yet.

Create desktop icon for shell script?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Create desktop icon for shell script?

    I have several smalll shell scripts that I use to run rsync between my machines to keep a common data directory synchronized between my 4 machines at home. In KDE4, I just dragged the shell script from Dolphin to a dekstop, then edited the icon properties to allow me to run the shell script in a terminal where I could keep tabs on what it was syncing.

    Dragging an executable shell script now produces a text only link on the activity / desktop. Clicking that link does seem to run the script, but with no terminal to see it in.

    I can run the shellscript from Dolphin by using the context menu, and choosing to run it in a terminal. That works the way it always did. I want to create a desktop shortcut that will do that, as I did in KDE4.

    Can it be done? How?

    Thanks.

    Frank.
    Linux: Powerful, open, elegant. Its all I use.

    #2
    There are a few ways to do this and here is a couple of them, both ways require editing of the .desktop file you created. If you dragged the script to desktop, the .desktop file should be in ~/.local/share/plasma_icons/ (if it's not there, post back...if you're using the "Folder View" -style desktop or dragged the script to a folder view widget, the .desktop file should in the directory the folder view is selected to show, commonly ~/Desktop).

    Open the .desktop file in kate, and

    1. edit:
    Type=Application
    (if you dragged the script to the desktop, this is probably "Type=Link" currently in the file)

    2.
    Remove the "URL" line (this only refers to type=link, which we changed in 1.)

    Then add either:
    3a.
    Exec=konsole -e "<your command>"
    (replace <your command> with the command you wish to run, for example Exec=konsole -e "/usr/local/bin/myscript")

    or
    3b.
    Terminal=true
    Exec=<your command>
    (replace '<your command>' with the command you wish to run, for example Exec=/usr/local/bin/myscript)

    4. You may also need to make the .desktop file executable (if it isn't, plasma should ask for confirmation on whether you wish to run it the first time)

    (If these don't work, please post back the contents of the .desktop file so we can have a look)
    Last edited by kubicle; Mar 25, 2018, 11:25 PM.

    Comment


      #3
      Kubicle:

      If you dragged the script to desktop, the .desktop file should be in ~/.local/share/plasma_icons/ (if it's not there, post back...if you're using the "Folder View" -style desktop or dragged the script to a folder view widget, the .desktop file should in the directory the folder view is selected to show, commonly ~/Desktop).
      None of the above.

      I did drag the script from Dolphin to the desktop, and got a text only 'icon' on the activity desktop. There is no pictorial icon with the text, nor are there any 'handles' to move it. All I can do is delete it from the right-click context menu. If I right click that 'icon' I get a popup labeled "Keyboard shortcuts" saying "The shortcut will activate the applet: It will give the applet..." And if I double click it (double click is my preference) it will indeed run the script, but blind. I have no idea of what it is doing as nothing appears on the desktop, or in a Konsole window.

      There is no ~/.local/share/plasma_icons/ folder. Only ~/.local/share/

      ~/Desktop is empty.

      I have 6 activities, each with a single desktop. I have no idea if it is currently in folder view or not, nor do I know how to find out.

      This is my first effort to actually USE Plasma 5, having come from KDE4 prior to this. I am floundering in the changes.

      Thanks for any help that can be given.

      Frank.
      Linux: Powerful, open, elegant. Its all I use.

      Comment


        #4
        Originally posted by Frank616 View Post
        Kubicle:



        None of the above.

        I did drag the script from Dolphin to the desktop, and got a text only 'icon' on the activity desktop. There is no pictorial icon with the text, nor are there any 'handles' to move it. All I can do is delete it from the right-click context menu. If I right click that 'icon' I get a popup labeled "Keyboard shortcuts" saying "The shortcut will activate the applet: It will give the applet..." And if I double click it (double click is my preference) it will indeed run the script, but blind. I have no idea of what it is doing as nothing appears on the desktop, or in a Konsole window.

        There is no ~/.local/share/plasma_icons/ folder. Only ~/.local/share/

        ~/Desktop is empty.

        I have 6 activities, each with a single desktop. I have no idea if it is currently in folder view or not, nor do I know how to find out.

        This is my first effort to actually USE Plasma 5, having come from KDE4 prior to this. I am floundering in the changes.

        Thanks for any help that can be given.

        Frank.
        Left click and hold briefly to bring up the "handle"

        Also make sure you unlock widgets.

        Right click on the desktop to bring up properties and settings, same as in KDE4
        Last edited by claydoh; Mar 29, 2018, 04:01 PM.

        Comment


          #5
          Originally posted by claydoh View Post
          Left click and hold briefly to bring up the "handle"

          Also make sure you unlock widgets.

          Right click on the desktop to bring up properties and settings, same as in KDE4
          Right... OK, got the handle and enlarged it so I can see the graphical icon, which is just a grey 'page' with >_ on it. I was able to move it with that handle as well. So far, so good.

          It appears that I have Desktop view selected. Do I want something else? What is the difference between Folder and Desktop views?

          I changed it from Desktop view to Folder view, and got a couple of new icons: "Home" and "Trash". Those do show up in the /home/frank/Desktop folder. No entry however for the script icon I created by dragging the script to the desktop. Still no apparent way to edit the dragged icon/link/shortcut to make it open Konsole and then run the script.

          I have since changed it back to Desktop view as I don't know what I'm doing in choosing one over the other.

          However, progress IS being made!

          Further help appreciated.

          Thanks.

          Frank.
          Linux: Powerful, open, elegant. Its all I use.

          Comment


            #6
            when you dragged the file over you should have been given a choice of "widget" note or icon , it seems you chose widget try again with the icon choice

            then the .desktop file will be where kubicle said

            VINNY
            i7 4core HT 8MB L3 2.9GHz
            16GB RAM
            Nvidia GTX 860M 4GB RAM 1152 cuda cores

            Comment


              #7
              Also, which plasma version are you using?
              There have been some changes between versions and older versions of plasma might handle these a bit differently.

              If you can't find the desktop file, you can search for it by running:
              (replace "name_of_the_icon" with the actual name)
              Code:
              find ~/.local/share -name 'name_of_the_icon.desktop'


              Comment


                #8
                Vinny:

                When I drag the executable bash text file script to the desktop from Dolphin, I get no choice. When I go to delete the created shortcut, I get a popup saying: Widget Removed

                Kubicle:

                I ran the search, and nothing showed. I will try to attach a screenshot. I just plain don't see my syncR-O.sh script/icon/shortcut/widget there anywhere. But yet, there it is to the left as big as life and twice as ugly. :-)

                Plasma is version 5.8.9.

                Frank.
                Attached Files
                Linux: Powerful, open, elegant. Its all I use.

                Comment


                  #9
                  Originally posted by Frank616 View Post
                  Plasma is version 5.8.9.
                  This might be the explanation why you aren't having success. I tested my instructions on my 5.12.4 and they work as expected, but unfortunately I don't use desktop icons myself so I have no recollection on how those were handled in 5.8.9 (like whether they were added as widgets rather than .desktop files if you drag-and-drop). But I'm fairly sure there have been changes between the versions.

                  You probably could add a .desktop file manually (I can even provide the steps for you if you wish), but the simplest solution I would recommend is to upgrade your plasma (you'd likely get a few extra benefits as well).

                  Do you plan to upgrade to the 18.04 LTS due for a release in April? (this should give you a fresh version of plasma among other things).

                  Comment


                    #10
                    Kubicle:

                    This might be the explanation why you aren't having success. I tested my instructions on my 5.12.4 and they work as expected, but unfortunately I don't use desktop icons myself so I have no recollection on how those were handled in 5.8.9 (like whether they were added as widgets rather than .desktop files if you drag-and-drop). But I'm fairly sure there have been changes between the versions.
                    So, is not 5.8.9 the version that ordinarily comes with 16.04?

                    Do you plan to upgrade to the 18.04 LTS due for a release in April? (this should give you a fresh version of plasma among other things).
                    Yes, but I need a machine that works now, unfortunately. Do your comments mean that 5.8.9 won't do what I need? I cannot create desktop shortcuts to shell scripts? If so, this is the reason why I stuck with 14.04 for so long. KDE 5 ain't done yet. :-) It would break my heart to have to hold off an upgrade yet again, but I need tools that work.

                    The only reason I have 16.04 on this machine is that it is a new Dell laptop, and it came with Ubuntu 16.04, onto which I immediately installed the KDE libraries. I tried using this machine with 14.04 but there appears to be no network adapter support for it in that version.

                    I'm happy to consider an alternative way of working. How do you launch commonly used shell scripts?

                    Thanks.

                    Frank.
                    Linux: Powerful, open, elegant. Its all I use.

                    Comment


                      #11
                      Originally posted by Frank616 View Post
                      So, is not 5.8.9 the version that ordinarily comes with 16.04?
                      It probably is, if you haven't enabled any kubuntu PPAs that possibly have more recent versions. I'm using KDE Neon, which is based on 16.04, but with the latest KDE software.

                      Originally posted by Frank616 View Post
                      Yes, but I need a machine that works now, unfortunately. Do your comments mean that 5.8.9 won't do what I need? I cannot create desktop shortcuts to shell scripts?
                      You can probably create .desktop shortcuts to shell scripts, but it seems the GUI drag-and-drop doesn't create them in that version.

                      You can try doing it manually, I can't say for sure this will work on your plasma, but I'm fairly confident it should:

                      1. Open kate and paste this:
                      (edit Exec, Name and Icon values as needed, The Exec value should point to the script/command you wish to run)
                      Code:
                      [Desktop Entry]
                      Categories=Qt;KDE;System;X-KDE-More;
                      Encoding=UTF-8
                      Exec=/path/to/your/script
                      Icon=applications-system
                      Name=Script
                      NoDisplay=false
                      StartupNotify=false
                      Terminal=true
                      Type=Application
                      Save that as ~/.local/share/applications/pick_a_name.desktop
                      (technically, the location doesn't matter, but putting it in ~/.local/share/applications/ should also make it appear in your application menu [kmenu])

                      2. Make the "pick_a_name.desktop" file executable. (Right-Click>Properties...)

                      3. Drag the "pick_a_name.desktop" file into the desktop...alternatively, you can search for it in your application menu and right-click>Add_to_Desktop

                      4. Bob's hopefully your uncle

                      Originally posted by Frank616 View Post
                      If so, this is the reason why I stuck with 14.04 for so long. KDE 5 ain't done yet. :-)
                      Well, it seems to work in the latest version (creating .desktop links that is)

                      Originally posted by Frank616 View Post
                      I'm happy to consider an alternative way of working. How do you launch commonly used shell scripts?
                      I'm a keyboard kind of guy, so I generally use keyboard shortcuts and shell aliases, but that's not everyone's cup of tea, so to speak.

                      EDIT: Greygeek's method (in the next post) is basically the GUI way of doing my step 1 (both create a .desktop file to launch your script in ~/.local/share/applications/)...so choose whichever you prefer.
                      Last edited by kubicle; Mar 30, 2018, 11:32 AM.

                      Comment


                        #12
                        Originally posted by Frank616 View Post
                        ....
                        I'm happy to consider an alternative way of working. How do you launch commonly used shell scripts?
                        As an executable shell script it should have its execute permission set. Then, what I usually do, is to "Edit Applications" from the KGears menu (left hand side of the panel) and locate where in the menu structure I want to put my application. Then I click on "Add an Item". In the right panel are two tabs. In the left tab I fill in the blanks and for the command path I browse to my script and select it. IF it needs to run as root I add "sudo " in from of it. I add an Icon (which I can choose from the menu that pops up when I click on the blank Icon button to the right of the "Name", or I can download an Icon from the Internet and browse to it. On the second tab I check the checkbox "Run in Terminal". Then I click the save button and then close the edit tool.
                        "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                        – John F. Kennedy, February 26, 1962.

                        Comment


                          #13
                          Kubicle:

                          I tried your instructions, and I did indeed succeed in creating a desktop link/icon/widget, complete with a default mulitocolored icon looking much like the default wallpaper. However, clicking it does nothing. I may have entered something incorrectly and have a syntax error. Sadly, I get no feedback as to what might have gone wrong. I'll try GreyGeek's method now.

                          Thanks for walking me through this.

                          Frank.
                          Linux: Powerful, open, elegant. Its all I use.

                          Comment


                            #14
                            GreyGeek:

                            OK, succeeded in setting this up, and it MAY have run, but I saw no terminal open.

                            I had to right click the Kmenu to open the Edit Applications. I was able to choose a black 'terminal' icon to identify it. I dragged that to the desktop, and it did produce the icon/shortcut/widget on the desktop. However, double clicking it did not open a terminal where I could see it run.

                            Does this produce a config file somewhere that I can check?

                            What am I doing wrong?

                            Frank.

                            Frank.
                            Linux: Powerful, open, elegant. Its all I use.

                            Comment


                              #15
                              Originally posted by Frank616 View Post
                              GreyGeek:

                              OK, succeeded in setting this up, and it MAY have run, but I saw no terminal open.

                              I had to right click the Kmenu to open the Edit Applications. I was able to choose a black 'terminal' icon to identify it. I dragged that to the desktop, and it did produce the icon/shortcut/widget on the desktop. However, double clicking it did not open a terminal where I could see it run.

                              Does this produce a config file somewhere that I can check?

                              What am I doing wrong?

                              Frank.

                              Frank.
                              On the second tab did you check the “Run in Terminal” box?
                              In the first tab did you put the complete path to the script, including the script name (Home/yourname/somedir/script.sh) in the Command line?
                              Does your script have the execute permission set?
                              Did you supply a name and description?



                              Sent from my iPhone using Tapatalk
                              "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                              – John F. Kennedy, February 26, 1962.

                              Comment

                              Working...
                              X