Results 1 to 6 of 6

Thread: Custom keyboard shortcuts to paste text

  1. #1
    Join Date
    Apr 2011
    Location
    Taiwan
    Beans
    8
    Distro
    Ubuntu 10.04 Lucid Lynx

    Custom keyboard shortcuts to paste text

    Hi all

    For my job, I have to send regular long-ish reports via a web interface. Obviously the reports vary depending on activity, but they always contain certain keywords, groups of words or expressions. Since I have to do this almost everyday, I'd like to speed up the process...
    Is there a way to create custom shortcuts that would enable me to paste text directly as I type my report? ie Ctrl+Shift+1 pastes keyword A, Ctrl+Shift+2 pastes expression B, etc.

    Firefox shortcuts (since I type directly in a web interface)? Apparently these control only Firefox features and browsing.
    Ubuntu shortcuts? Same issue.
    Text editor shortcuts?

    Any ideas welcome!
    Thanks in advance.

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Custom keyboard shortcuts to paste text

    first install these tools
    Code:
    sudo apt-get install xdotool xsel
    predefined text can be pasted like this:
    text typed explicitly
    Code:
    echo "text to paste" | xsel -pi; xdotool click 2
    text from file
    Code:
    xsel -pi < text_to_paste.txt; xdotool click 2
    xsel puts the text in (-i) the primary buffer (-p), which then gets pasted with middle click, emulated by xdotool.

    create a key combo enter the code below
    Code:
    sh -c 'echo "some text to paste" | xsel -pi; xdotool click 2'
    or
    Code:
    sh -c 'xsel -pi < text_to_paste.txt; xdotool click 2'
    hotkeys don't like multiple commands so sh -c wraps everything up and acts as 1 cmd.
    Last edited by Vaphell; October 16th, 2012 at 12:59 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Apr 2011
    Location
    Taiwan
    Beans
    8
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Custom keyboard shortcuts to paste text

    This looks great, thanks a lot! I knew there must be something like this.

    I'll have a closer look at this and get back to you...

    Thanks again!

  4. #4
    Join Date
    Oct 2010
    Location
    Sweden
    Beans
    664
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Custom keyboard shortcuts to paste text

    Quote Originally Posted by Vaphell View Post
    first install these tools
    Code:
    sudo apt-get install xdotool xsel
    predefined text can be pasted like this:
    text typed explicitly
    Code:
    echo "text to paste" | xsel -pi; xdotool click 2
    text from file
    Code:
    xsel -pi < text_to_paste.txt; xdotool click 2
    xsel puts the text in (-i) the primary buffer (-p), which then gets pasted with middle click, emulated by xdotool.

    create a key combo enter the code below
    Code:
    sh -c 'echo "some text to paste" | xsel -pi; xdotool click 2'
    or
    Code:
    sh -c 'xsel -pi < text_to_paste.txt; xdotool click 2'
    hotkeys don't like multiple commands so sh -c wraps everything up and acts as 1 cmd.
    This looks great, but I need some clarification.
    Could you please walk me through setting this up step by step?
    I installed xdotool xsel, but am lost after that.
    Thank you,
    GG -----------
    GUI we don't need no stinking GUI: A collection of Bash scripts
    Mutt (email), cmus (music),Google Calendar and Google Tasks cli

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Custom keyboard shortcuts to paste text

    what do you want to achieve exactly?
    either way you have to go to the hotkey config, create new entry and fill it with sh -c '<something>', where <something> is the xsel/xdotool sequence that does what you need.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #6
    Join Date
    Oct 2010
    Location
    Sweden
    Beans
    664
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Custom keyboard shortcuts to paste text

    Quote Originally Posted by Vaphell View Post
    what do you want to achieve exactly?
    either way you have to go to the hotkey config, create new entry and fill it with sh -c '<something>', where <something> is the xsel/xdotool sequence that does what you need.
    OK, I just tried again and it seems to be working now. I guess I didn't read carefully enough.
    Thank you.
    Last edited by GrouchyGaijin; January 8th, 2013 at 09:26 PM. Reason: Update
    Thank you,
    GG -----------
    GUI we don't need no stinking GUI: A collection of Bash scripts
    Mutt (email), cmus (music),Google Calendar and Google Tasks cli

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •