Announcement

Collapse
No announcement yet.

Get file name from dolphin after right clicking on an icon and Open With bash script

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

    [DESKTOP] Get file name from dolphin after right clicking on an icon and Open With bash script

    How do I write a bash script so that when I right click on an icon for a normal file in dolphin and select Open With my script, my script gets the file name that the icon represents?

    E.g. The icon shows "somefile.txt" and that gets passed to my script so I can process the file "somefile.txt".

    I'm using kubuntu 16.04 with KDE 5.18.0, dolphin 15.12.3.
    kubuntu Xenial - Toshiba i3 and Toshiba i7 Notebooks

    #2
    KDE service/context menus

    Maybe you are looking KDE service/context menus ?

    https://techbase.kde.org/Development..._Service_Menus :

    Introduction

    In KDE-speak a "servicemenu" is a special entry that appears in a context menu (or other context-based interface) for a file (or for directory), depending on the type of files that are selected.

    For example, if you have the KDE file archive utility Ark installed you will see a menu entry to "Extract here..." whenever you right click on a file archive. The option to "Extract here..." is a servicemenu...

    Where the Servicemenus Locate

    Servicemenus are defined using .desktop files, which are the same kind of files that are used to create entries in the K Menu or on the KDE desktop. These servicemenu files are found in...
    Note !
    With the KDE Framework 5 the service menu desktop files are looked at the:

    Code:
    $ kf5-config --path services
    KF5 service menus are at:

    ~/.local/share/kservices5/ServiceMenus/
    and
    /usr/share/kservices5/ServiceMenus/

    .desktop files

    The KDE is following the freedesktop org specifications - Desktop Entry Specification: https://standards.freedesktop.org/de...y-spec/latest/

    The Exec key: https://standards.freedesktop.org/de...t/ar01s06.html
    The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments...

    Recognized field codes are as follows:

    %f A single file name (including the path), even if multiple files are selected...
    A short example:

    Making $HOME/.local/share/kservices5/ServiceMenus/dosomething.desktop:
    Code:
    [Desktop Entry]
    Type=Service
    Icon=edit-redo
    X-KDE-ServiceTypes=KonqPopupMenu/Plugin
    MimeType=all/allfiles;
    Actions=doSomething;
    X-KDE-Priority=TopLevel
    #X-KDE-Submenu=
    Encoding=UTF-8
    
    [Desktop Action doSomething]
    Name=Do Something
    Icon=edit-redo
    Exec=kdialog --msgbox "You have right clicked %f"


    Shell Scripting with KDE Dialogs: https://techbase.kde.org/Development...th_KDE_Dialogs
    Last edited by Rog131; May 28, 2017, 09:46 AM.
    Before you edit, BACKUP !

    Why there are dead links ?
    1. Thread: Please explain how to access old kubuntu forum posts
    2. Thread: Lost Information

    Comment


      #3
      Thanks for the fast reply.

      If read this correctly, you're saying that I have to build my application(s) into the KDE framework. That will be a bit of a learning curve. I have looked at desktop files before, but haven't created any. My system seems to have very few of these in /usr/share/kservices5/ServiceMenus/. The user directory didn't even exist until I just created it.

      I was hoping for something more a bit more ad hoc. A lot of things I create are quick utilities or experiments, not polished applications.

      I will study this information further. It looks like it will be relatively easy to do once I actually figure it out. Is there a simplified tutorial somewhere? I have looked briefly at free desktop stuff before and it's pretty dense.

      Originally posted by Rog131 View Post
      https://techbase.kde.org/Development..._Service_Menus :

      Note !
      With the KDE Framework 5 the service menu desktop files are looked at the:

      Code:
      $ kf5-config --path services
      KF5 service menus are at:

      ~/.local/share/kservices5/ServiceMenus/
      and
      /usr/share/kservices5/ServiceMenus/

      .desktop files

      The KDE is following the freedesktop org specifications - Desktop Entry Specification: https://standards.freedesktop.org/de...y-spec/latest/

      The Exec key: https://standards.freedesktop.org/de...t/ar01s06.html
      kubuntu Xenial - Toshiba i3 and Toshiba i7 Notebooks

      Comment


        #4
        I just followed the tutorial link you already provided. It looks more readable that what I have seen in the past. I'll start with that.
        kubuntu Xenial - Toshiba i3 and Toshiba i7 Notebooks

        Comment


          #5
          Originally posted by jonathan9 View Post

          If read this correctly, you're saying that I have to build my application(s) into the KDE framework...

          I was hoping for something more a bit more ad hoc. A lot of things I create are quick utilities or experiments, not polished applications.

          I will study this information further. It looks like it will be relatively easy to do once I actually figure it out. Is there a simplified tutorial somewhere? I have looked briefly at free desktop stuff before and it's pretty dense.
          Well ... ? ... I'm writing that there is an option to add menu options to the KDE file managers and to the plasma folder view plasmoid. They are all using same service menus.

          To add a menu option create a desktop file:

          Code:
          [Desktop Entry]
          Type=Service
          Icon=edit-redo
          X-KDE-ServiceTypes=KonqPopupMenu/Plugin
          MimeType=all/allfiles;
          Actions=doSomething;
          X-KDE-Priority=TopLevel
          X-KDE-Submenu=Open With
          Encoding=UTF-8
          
          [Desktop Action doSomething]
          Name=Do Something
          Icon=edit-redo
          Exec=MyScript.sh "%f"
          This will add another 'Open With' sub menu for your script:



          Your MyScript.sh cold be:

          Code:
          #!/bin/sh
          
          kdialog --msgbox "You have right clicked $1"
          Script will read the passed file argument (%f -> $1) - Positional Parameters: https://www.gnu.org/software/bash/ma...nal-Parameters .
          Last edited by Rog131; May 28, 2017, 10:29 AM.
          Before you edit, BACKUP !

          Why there are dead links ?
          1. Thread: Please explain how to access old kubuntu forum posts
          2. Thread: Lost Information

          Comment


            #6
            Sorry

            I was really tired when I last responded to you. I can see now that you gave me everything I needed to get started and then some.

            Thanks a lot.

            Originally posted by Rog131 View Post
            Well ... ? ... I'm writing that there is an option to add menu options to the KDE file managers and to the plasma folder view plasmoid. They are all using same service menus.

            To add a menu option create a desktop file:

            Code:
            [Desktop Entry]
            Type=Service
            Icon=edit-redo
            X-KDE-ServiceTypes=KonqPopupMenu/Plugin
            MimeType=all/allfiles;
            Actions=doSomething;
            X-KDE-Priority=TopLevel
            X-KDE-Submenu=Open With
            Encoding=UTF-8
            
            [Desktop Action doSomething]
            Name=Do Something
            Icon=edit-redo
            Exec=MyScript.sh "%f"
            This will add another 'Open With' sub menu for your script:



            Your MyScript.sh cold be:

            Code:
            #!/bin/sh
            
            kdialog --msgbox "You have right clicked $1"
            Script will read the passed file argument (%f -> $1) - Positional Parameters: https://www.gnu.org/software/bash/ma...nal-Parameters .
            kubuntu Xenial - Toshiba i3 and Toshiba i7 Notebooks

            Comment

            Working...
            X