Announcement

Collapse
No announcement yet.

Is it possible to run this qdbus command as a keyboard shortcut?

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

    Is it possible to run this qdbus command as a keyboard shortcut?

    Inspired by

    http://milianw.de/code-snippets/acce...cli-under-kde4

    I decided to try to make this command

    Code:
    qdbus org.kde.klipper /klipper getClipboardContents
    which dumps the current clipboard entry to stdout, a keyboard shortcut.

    It works fine on the command line (using konsole).

    I'd like to set it up as a keyboard shortcut dumping to a file:

    Code:
    qdbus org.kde.klipper /klipper getClipboardContents >> ~/recipes/RecipeLog.txt
    But so far no joy.

    The problem is not with setting up the key. if I instead use

    Code:
    echo $(date) >> ~/recipes/RecipeLog.txt
    there is output.

    Is it possible to make this work?

    TIA

    #2
    Yes, with the custom shortcuts you can set a keysequence to do just about anything

    System settings > shortcuts and gestures > custom shortcuts.

    Comment


      #3
      Thanks. Yes that is where I placed the command. Other things will work there, but not this.

      I wonder what is different about how a keyboard shortcut is executed compared to something done on the command line.

      Comment


        #4
        Replace "~" with "$HOME"

        ~ is expanded by bash, which might not be the shell that is running the command.

        Also try &>> to dump stdout and stderr to the file.

        Alternatively, create a script with the command you want and set that to run when you press the shortcut.
        Last edited by james147; Dec 23, 2012, 07:05 PM.

        Comment


          #5
          Thanks again for your help. Sadly, still nothing.

          Comment


            #6
            Solved

            Well, a miracle has happened. With no ideas left, I tried the command in pieces. First

            qdbus >> ~/recipes/RecipeLog.txt

            and there was output. The same as the output the command got in konsole. Then I tried

            qdbus org.kde.klipper >> ~/recipes/RecipeLog.txt

            and the same wonderful news. And the same for

            qdbus org.kde.klipper /klipper >> ~/recipes/RecipeLog.txt

            and finally

            qdbus org.kde.klipper /klipper getClipboardContents >> ~/recipes/RecipeLog.txt

            I have no clue what was wrong except that I probably (it was hours ago I decided to try this "quick" little feature!!) pasted the line directly from the blog so maybe there was some mysterious invisible character I copied by mistake?

            Anyway, this is quite a nice feature now: highlight information and save it to a file in one keystroke!

            Thanks again, James147.
            Last edited by esekyavuz; Dec 23, 2012, 09:02 PM.

            Comment


              #7
              Note: you could also do this via the clipboard actions using klipper by adding a custom action

              Comment


                #8
                Thanks for pointing that out! I added a shortcut there to edit the clipboard. So now it's just a couple of keystrokes to get some random text copied onto the clipboard, the text edited (maybe a note added to explain why it's being clipped), and then into a file. I think the next thing would be to get it to automatically add the source (URL/pdf filename).

                Comment


                  #9
                  From the KDE help pages for klipper:
                  Note that %s in the command line is replaced with the clipboard contents, e.g. if your command definition is kwrite %s and your clipboard contents are /home/phil/textfile, the command kwrite /home/phil/textfile will be run. To include %s in the command line, escape it with a backslash, as so: \%s.
                  For desktop files/menu entries you can also use:
                  %f %F files (single, list)
                  %u %U url (single, list)
                  %d %D directories (single, list)
                  Last edited by james147; Dec 24, 2012, 03:00 PM.

                  Comment

                  Working...
                  X