Announcement

Collapse
No announcement yet.

Help Writing A Service Menu

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

    [SOLVED] Help Writing A Service Menu

    I have written a service menu for KDE. It shows up in the menu, but has trouble reading the exec line at the end of the script. Here is the script: http://pastebin.com/2Uubw2vZ Maybe some one can point me in the right direction? I want to create a service menu for a few different apps, so a tutorial or just proper example using my script would hopefully point me in the right direction to create more menus.

    EDIT: Here is the service menu I created as a result of the syntax provided by OneLine: http://pastebin.com/nUJdhx9x Ins tructions are on the top of the file and can be safely left in the service menu.
    Last edited by Xplorer4x4; Jul 04, 2012, 01:28 PM.
    OS: Kubuntu 12.10/Windows 8
    CPU: Intel Core i7 2600K
    Motherboard: Gigabyte GA-Z77X-UD5H
    Memory: 2x4GB Corsair Dominator
    Graphics Card: MSI R7770
    Monitor: Dell 2208WFP
    Mouse: Mionix NAOS 5000
    PSU: Corsair 520HX
    Case: Thermaltake Mozart TX
    Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
    Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

    #2
    The only thing I see missing is the path, which in this case would be '.', so the line maybe should be written as:

    Exec=konsole --workdir %f && find . -type f -name *.rar -exec unrar e {} \;
    Using Kubuntu Linux since March 23, 2007
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Thanks for the quick reply snowhog, I tried that but it still can not process the exec field. I also tested the exec command from my pastebin directly in konsole, and it worked fine. It is only when trying to execute it from a .desktop that it fails to search a folder for .rar files.
      OS: Kubuntu 12.10/Windows 8
      CPU: Intel Core i7 2600K
      Motherboard: Gigabyte GA-Z77X-UD5H
      Memory: 2x4GB Corsair Dominator
      Graphics Card: MSI R7770
      Monitor: Dell 2208WFP
      Mouse: Mionix NAOS 5000
      PSU: Corsair 520HX
      Case: Thermaltake Mozart TX
      Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
      Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

      Comment


        #4
        Looked at the find command manual again. You are missing the single quotes around the braces, so the command needs to be written as:

        Exec=konsole --workdir %f && find . -type f -name *.rar -exec unrar e '{}' \;

        Last edited by Snowhog; Jun 24, 2012, 11:58 AM.
        Using Kubuntu Linux since March 23, 2007
        "It is a capital mistake to theorize before one has data." - Sherlock Holmes

        Comment


          #5
          Thanks but still not executing. I would imagine the error is logged in detail some where on my system, right? Which error log would it be in? Maybe that can produce a more specific error then it fails to execute the exec line.
          OS: Kubuntu 12.10/Windows 8
          CPU: Intel Core i7 2600K
          Motherboard: Gigabyte GA-Z77X-UD5H
          Memory: 2x4GB Corsair Dominator
          Graphics Card: MSI R7770
          Monitor: Dell 2208WFP
          Mouse: Mionix NAOS 5000
          PSU: Corsair 520HX
          Case: Thermaltake Mozart TX
          Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
          Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

          Comment


            #6
            Obviously it is best to stick to the basics to solve this problem, but I was hopping to exapnd the command slightly to function like this(in php terms-note my php is a bit rusty ):
            PHP Code:
            if find part01.rar{
            unrar e somefile
            }else if .rar{
            unrar e somefile.rar

            OS: Kubuntu 12.10/Windows 8
            CPU: Intel Core i7 2600K
            Motherboard: Gigabyte GA-Z77X-UD5H
            Memory: 2x4GB Corsair Dominator
            Graphics Card: MSI R7770
            Monitor: Dell 2208WFP
            Mouse: Mionix NAOS 5000
            PSU: Corsair 520HX
            Case: Thermaltake Mozart TX
            Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
            Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

            Comment


              #7
              Service Menus

              KDE Service Menus

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

              Error Messages

              http://techbase.kde.org/Development/...Error_Messages
              When you are debugging it is best to simply start a konsole and start the application (with this the command) from there.

              Example

              Original: Exec=konsole --workdir %f && find -type f -name *.rar -exec unrar e '{}' \;

              If you want to launch a konsole (and keep it open after the execution) and execute the find&unar

              Code:
              Exec=konsole --hold --workdir %f  -e find -type f -name '*.rar' -exec unrar e {} \;
              This will open a konsole to the workdir and execute the find&unrar there.

              The -name '*.rar' : http://askubuntu.com/questions/30330...files-in-the-c


              man kosole
              --workdir <dir> Set the initial working directory of the new tab or window to 'dir'
              --hold, --noclose Do not close the initial session automatically when it ends.
              -e <cmd> Command to execute (the find&unrar)
              If you want to execute the find&unrar without the output, you don't need the konsole.

              Code:
              Exec=find %f -type f -name '*.rar' -exec unrar e '{}' %f \;
              This will search the directory %f and unrar to the %f.
              Last edited by OneLine; Jun 24, 2012, 01:20 PM.
              Have you tried ?

              - How to Ask a Question on the Internet and Get It Answered
              - How To Ask Questions The Smart Way

              Comment


                #8
                OneLine, thanks for all the info, butI tried your Exec lines in the script but it still fails to execute.
                OS: Kubuntu 12.10/Windows 8
                CPU: Intel Core i7 2600K
                Motherboard: Gigabyte GA-Z77X-UD5H
                Memory: 2x4GB Corsair Dominator
                Graphics Card: MSI R7770
                Monitor: Dell 2208WFP
                Mouse: Mionix NAOS 5000
                PSU: Corsair 520HX
                Case: Thermaltake Mozart TX
                Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                Comment


                  #9
                  It's not the ideal/proper way, but I found a working solution:
                  Code:
                  Exec=konsole --hold --workdir %f -e sh /home/xplorer4x4/searchforrars.sh
                  searchforrars.sh:
                  Code:
                  find -type f -name *.rar -exec unrar e {} \;
                  OS: Kubuntu 12.10/Windows 8
                  CPU: Intel Core i7 2600K
                  Motherboard: Gigabyte GA-Z77X-UD5H
                  Memory: 2x4GB Corsair Dominator
                  Graphics Card: MSI R7770
                  Monitor: Dell 2208WFP
                  Mouse: Mionix NAOS 5000
                  PSU: Corsair 520HX
                  Case: Thermaltake Mozart TX
                  Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                  Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                  Comment


                    #10
                    Manuals &amp; Errors

                    Trying with the:

                    Code:
                    [Desktop Entry]
                    Type=Service
                    X-KDE-ServiceTypes=KonqPopupMenu/Plugin,inode/directory
                    Actions=openTerminalHereToUnrar;
                    
                    [Desktop Action openTerminalHereToUnrar]
                    Name=Search for RARs
                    Icon=utilities-file-archiver
                    Exec=konsole --hold --workdir %f -e find -type f -name '*.rar' -exec unrar e '{}' \;
                    An error:


                    http://techbase.kde.org/Development/...Error_Messages
                    The debug messages get redirected into the file ~/.xsession-errors or ~/.X.err in your home directory (that is with a leading dot '.' also watch the Capital).
                    The ~/.xsession-errors:
                    "KConfigIni: In file.../.kde/share/kde4/services/ServiceMenus/find_unrar.desktop, line 9: " "Invalid escape sequence "\;"."
                    The man find:
                    ... The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also.
                    Changing the "\;" to the " ';' "

                    =>
                    Testing with the:
                    Code:
                    [Desktop Entry]
                    Type=Service
                    X-KDE-ServiceTypes=KonqPopupMenu/Plugin,inode/directory
                    Actions=openTerminalHereToUnrar;
                    
                    [Desktop Action openTerminalHereToUnrar]
                    Name=Search for RARs
                    Icon=utilities-file-archiver
                    Exec=konsole --hold --workdir %f -e find -type f -name '*.rar' -exec unrar e '{}' ';'


                    Working at here.
                    Have you tried ?

                    - How to Ask a Question on the Internet and Get It Answered
                    - How To Ask Questions The Smart Way

                    Comment


                      #11
                      Nice work. I had no doubt that you would come up with solution.
                      Using Kubuntu Linux since March 23, 2007
                      "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                      Comment


                        #12
                        Thanks I will look at that when I get home but is is possible to include a check in there to try to find part01.rar and .rar but exclude part0*.rar and part 1*.rar and part 2* and so on?
                        OS: Kubuntu 12.10/Windows 8
                        CPU: Intel Core i7 2600K
                        Motherboard: Gigabyte GA-Z77X-UD5H
                        Memory: 2x4GB Corsair Dominator
                        Graphics Card: MSI R7770
                        Monitor: Dell 2208WFP
                        Mouse: Mionix NAOS 5000
                        PSU: Corsair 520HX
                        Case: Thermaltake Mozart TX
                        Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                        Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                        Comment


                          #13
                          Little bump here, I tried to google this but no luck..is it possible to make comments in these menus?

                          EDIT: I figured out it can be done using #
                          Last edited by Xplorer4x4; Jun 25, 2012, 10:19 PM.
                          OS: Kubuntu 12.10/Windows 8
                          CPU: Intel Core i7 2600K
                          Motherboard: Gigabyte GA-Z77X-UD5H
                          Memory: 2x4GB Corsair Dominator
                          Graphics Card: MSI R7770
                          Monitor: Dell 2208WFP
                          Mouse: Mionix NAOS 5000
                          PSU: Corsair 520HX
                          Case: Thermaltake Mozart TX
                          Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                          Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                          Comment


                            #14
                            Some more questions:
                            1. I also have some more service menu questions, is the Exec line simply bash commands like you would enter in Konsole?
                            2. Is it possible to execute commands from the exec line in a progressive matter? For example you select 4 folders with split RAR archives. I assume I would need to use ark directly rather then unrar? Would I need to resort to executing a shell script instead?
                            3.Where is the "move to trash" context menu entry located? I can't seem to find it.

                            Snowhog if you have any more links for more in-depth reading on the service menus and other context menu functions I would greatly appreciate the reading material.
                            OS: Kubuntu 12.10/Windows 8
                            CPU: Intel Core i7 2600K
                            Motherboard: Gigabyte GA-Z77X-UD5H
                            Memory: 2x4GB Corsair Dominator
                            Graphics Card: MSI R7770
                            Monitor: Dell 2208WFP
                            Mouse: Mionix NAOS 5000
                            PSU: Corsair 520HX
                            Case: Thermaltake Mozart TX
                            Cooling: Thermalright TRUE Black Ultra-120 eXtreme CPU Heatsink Rev C
                            Hard Drives: 1x180 GB Intel 330 SSD - 1xWD 1 TB Caviar Black - 1xWD 2 TB Caviar Green - 2xWD 3 TB Caviar Green

                            Comment


                              #15
                              Specifications etc...

                              1. I also have some more service menu questions, is the Exec line simply bash commands like you would enter in Konsole?
                              The Exec or the "The Exec key" is
                              http://www.freedesktop.org/wiki/
                              --> http://www.freedesktop.org/wiki/Specifications
                              ----> http://standards.freedesktop.org/des...y-spec/latest/
                              The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment. The name or path of the executable program may not contain the equal sign ("="). Arguments are separated by a space.

                              Arguments may be quoted in whole. If an argument contains a reserved character the argument must be quoted. The rules for quoting of arguments is also applicable to the executable name or path of the executable program as provided.

                              Quoting must be done by enclosing...
                              ++ lot of stuf. The KDE (and the Gnome) are more or less using the freedesktop specifications (Specifications - These are not really standards ).

                              2. Is it possible to execute commands from the exec line in a progressive matter?
                              Hmm ??

                              With a service menu you could:

                              - execute a command or program.
                              - multiple commands - an opinion: It is easier to put the commands to the external script file. The debugging is easier - you can execute the script file from the konsole and get the error messages immediately.


                              3.Where is the "move to trash" context menu entry located? I can't seem to find it.
                              If you mean the Dolphin's "move to trash". It is not a service menu. The Dolphin is using the KDE KIO: http://en.wikipedia.org/wiki/KIO

                              ktrash --help:
                              Usage: ktrash [Qt-options] [KDE-options] [options] [ignored]

                              Helper program to handle the KDE trash can
                              Note: to move files to the trash, do not use ktrash, but "kioclient move 'url' trash:/"

                              Generic options:
                              --help Show help about options
                              --help-qt Show Qt specific options
                              --help-kde Show KDE specific options
                              --help-all Show all options
                              --author Show author information
                              -v, --version Show version information
                              --license Show license information
                              -- End of options

                              Options:
                              --empty Empty the contents of the trash
                              --restore <file> Restore a trashed file to its original location

                              Arguments:
                              ignored Ignored
                              Earlier; Kubuntuforums: http://www.kubuntuforums.net/showthr...ash-bin-access


                              Note ! You could launch the "move to trash" through the Dolphin with the D-BUs call: http://www.freedesktop.org/wiki/Software/dbus



                              KDE TechBase: http://techbase.kde.org/Development/...s/Introduction
                              qdbus

                              qdbus is a command line tool which can be used to list the services, objects and interfaces on a given bus as well as send messages to a given address on the bus. It can be used to explore both the system and the default session bus. If the --system switch is passed, qdbus will connect to the system bus, otherwise it uses the session bus.

                              qdbus uses the rest of the supplied arguments on the command as an address and, if any, parameters to pass to a given object. If a full address is not supplied, then it lists all the objects available from that point on the bus. For instance, if no addresses are provided a list of available services is listed. If a service name is provided, object paths will be provided. If a path is also provided all methods in all interfaces will be listed. In this way one can quite easily explore and interact with objects on the bus, making qdbus very useful for testing, scripting and even idle exploration.
                              qdbusviewer

                              qdbusviewer is a Qt application that provides a graphical interface to essentially the same set of features that qdbus provides on the command line, thus providing a more user friendly mechanism to interact with the bus. qdbusviewer ships with Qt4 itself and is easy for anyone who is familiar with the basic D-Bus concepts, such as object addresses, to use.

                              More

                              KDE (Dolphin) Service Menu examples:

                              Kubuntu forums:http://www.kubuntuforums.net/showthr...s-with-Dolphin
                              KDE-Look: http://kde-look.org/index.php?xcontentmode=287
                              Last edited by OneLine; Jun 27, 2012, 02:45 AM.
                              Have you tried ?

                              - How to Ask a Question on the Internet and Get It Answered
                              - How To Ask Questions The Smart Way

                              Comment

                              Working...
                              X