How do I make a keyboard shortcut for code which uses xsel?











up vote
0
down vote

favorite
1












OS: Kubuntu 18.04 or Ubuntu 18.04



I want to remove the first seven characters of certain strings I copy. For example, I want to first copy and then convert



1234567890


to



890


I can do so with the following code:



xsel -b -o | cut -c 8-


I can put the code into a simple script and can run that script successfully in a terminal.



#!/bin/bash
xsel -b -o | cut -c 8-


But that does not help to paste the modified contents into a GUI-based text file . So I assigned keyboard shortcuts to the code directly or to the corresponding script. But either way, nothing happens in Kubuntu 18.04 or in Ubuntu 18.04 when I press the assigned keyboard shortcut.



Even



#!/bin/bash
bash -c 'xsel -b -o | cut -c 8-'


does not work.



Why is that? Is is something peculiar to xsel (and to xclip which poses the same issue)?










share|improve this question
























  • Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
    – Byte Commander
    yesterday










  • I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
    – DK Bose
    yesterday






  • 1




    Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
    – vanadium
    yesterday










  • Thanks, I'll try that as well.
    – DK Bose
    yesterday















up vote
0
down vote

favorite
1












OS: Kubuntu 18.04 or Ubuntu 18.04



I want to remove the first seven characters of certain strings I copy. For example, I want to first copy and then convert



1234567890


to



890


I can do so with the following code:



xsel -b -o | cut -c 8-


I can put the code into a simple script and can run that script successfully in a terminal.



#!/bin/bash
xsel -b -o | cut -c 8-


But that does not help to paste the modified contents into a GUI-based text file . So I assigned keyboard shortcuts to the code directly or to the corresponding script. But either way, nothing happens in Kubuntu 18.04 or in Ubuntu 18.04 when I press the assigned keyboard shortcut.



Even



#!/bin/bash
bash -c 'xsel -b -o | cut -c 8-'


does not work.



Why is that? Is is something peculiar to xsel (and to xclip which poses the same issue)?










share|improve this question
























  • Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
    – Byte Commander
    yesterday










  • I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
    – DK Bose
    yesterday






  • 1




    Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
    – vanadium
    yesterday










  • Thanks, I'll try that as well.
    – DK Bose
    yesterday













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





OS: Kubuntu 18.04 or Ubuntu 18.04



I want to remove the first seven characters of certain strings I copy. For example, I want to first copy and then convert



1234567890


to



890


I can do so with the following code:



xsel -b -o | cut -c 8-


I can put the code into a simple script and can run that script successfully in a terminal.



#!/bin/bash
xsel -b -o | cut -c 8-


But that does not help to paste the modified contents into a GUI-based text file . So I assigned keyboard shortcuts to the code directly or to the corresponding script. But either way, nothing happens in Kubuntu 18.04 or in Ubuntu 18.04 when I press the assigned keyboard shortcut.



Even



#!/bin/bash
bash -c 'xsel -b -o | cut -c 8-'


does not work.



Why is that? Is is something peculiar to xsel (and to xclip which poses the same issue)?










share|improve this question















OS: Kubuntu 18.04 or Ubuntu 18.04



I want to remove the first seven characters of certain strings I copy. For example, I want to first copy and then convert



1234567890


to



890


I can do so with the following code:



xsel -b -o | cut -c 8-


I can put the code into a simple script and can run that script successfully in a terminal.



#!/bin/bash
xsel -b -o | cut -c 8-


But that does not help to paste the modified contents into a GUI-based text file . So I assigned keyboard shortcuts to the code directly or to the corresponding script. But either way, nothing happens in Kubuntu 18.04 or in Ubuntu 18.04 when I press the assigned keyboard shortcut.



Even



#!/bin/bash
bash -c 'xsel -b -o | cut -c 8-'


does not work.



Why is that? Is is something peculiar to xsel (and to xclip which poses the same issue)?







command-line shortcut-keys xclip xsel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









DK Bose

11.5k113681




11.5k113681












  • Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
    – Byte Commander
    yesterday










  • I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
    – DK Bose
    yesterday






  • 1




    Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
    – vanadium
    yesterday










  • Thanks, I'll try that as well.
    – DK Bose
    yesterday


















  • Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
    – Byte Commander
    yesterday










  • I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
    – DK Bose
    yesterday






  • 1




    Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
    – vanadium
    yesterday










  • Thanks, I'll try that as well.
    – DK Bose
    yesterday
















Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
– Byte Commander
yesterday




Keyboard shortcuts don't run in a shell, so you can not use stuff like pipes directly. You need to wrap the command in a bash -c '...' then or put it in a script file which you can call. Also as it is, your script/command outputs to the console, which is nonexistent when it runs as a keyboard shortcut. What do you want to happen with the result? Put it back into the clipboard? Append it to a fixed text file? Pop up a notification? You can also automatically watch for clipboard events and modify the contents instantly without extra shortcut, if that is what you need. Please clarify.
– Byte Commander
yesterday












I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
– DK Bose
yesterday




I tried the bash -c route as well but had the same result. I want the modified string to be pasted into a GUI-based text editor or the terminal. No, I don't want to automatically watch for clipboard events.
– DK Bose
yesterday




1




1




Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
– vanadium
yesterday




Use xdotool in your bash script to simulate keystrokes for cutting and pasting text in your application, i.e. xdotool key ctrl+x to cut text to the clipboard
– vanadium
yesterday












Thanks, I'll try that as well.
– DK Bose
yesterday




Thanks, I'll try that as well.
– DK Bose
yesterday










1 Answer
1






active

oldest

votes

















up vote
0
down vote













This script works when bound to a keyboard shortcut:



#!/bin/bash

xsel -b -o | cut -c 8- | tr -d 'n' | xsel -b -i


After running the script, the trimmed string can be pasted into the destination file using standard paste methods.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092224%2fhow-do-i-make-a-keyboard-shortcut-for-code-which-uses-xsel%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This script works when bound to a keyboard shortcut:



    #!/bin/bash

    xsel -b -o | cut -c 8- | tr -d 'n' | xsel -b -i


    After running the script, the trimmed string can be pasted into the destination file using standard paste methods.






    share|improve this answer



























      up vote
      0
      down vote













      This script works when bound to a keyboard shortcut:



      #!/bin/bash

      xsel -b -o | cut -c 8- | tr -d 'n' | xsel -b -i


      After running the script, the trimmed string can be pasted into the destination file using standard paste methods.






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        This script works when bound to a keyboard shortcut:



        #!/bin/bash

        xsel -b -o | cut -c 8- | tr -d 'n' | xsel -b -i


        After running the script, the trimmed string can be pasted into the destination file using standard paste methods.






        share|improve this answer














        This script works when bound to a keyboard shortcut:



        #!/bin/bash

        xsel -b -o | cut -c 8- | tr -d 'n' | xsel -b -i


        After running the script, the trimmed string can be pasted into the destination file using standard paste methods.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 9 hours ago

























        answered yesterday









        DK Bose

        11.5k113681




        11.5k113681






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092224%2fhow-do-i-make-a-keyboard-shortcut-for-code-which-uses-xsel%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?