Results 1 to 7 of 7

Thread: Is there a clipboard manager (or other way) that can do this?

  1. #1
    Join Date
    Sep 2012
    Beans
    6

    Is there a clipboard manager (or other way) that can do this?

    Suppose I want to copy a name, say "Bob Smith", and an email, say "bsmith@clipit.rspwn.com" from a document, into
    a form that has three fields:
    (1) "First Name", (1) "Last Name", and (3) email
    I would like to be able to copy "Bob", then copy "Smith", then "copy bobsmith@clipit.rspwn.com" and then go to the form and paste one after the other. It would be nice if after I pasted one, it was deleted from ClipIt so I don't even have to go to the history and select the next one, it's already loaded and ready to go. I think a fitting name could be "pop mode" where after you paste
    something, that entry just pop's off.

    I find myself in the above situation every day and would like to solve this problem.

    I posted a feature request for ClipIt here:

    https://github.com/shantzu/ClipIt/issues/17

    I know C++ and would be willing to try to implement this proposed feature in a C or C++ based clipboard manager if someone could guide me.

    Thanks,

    Scott

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

    Re: Is there a clipboard manager (or other way) that can do this?

    it should be rather easy to whip up few short scripts to do something like that, using xsel, xdotool and zenity in case of guification and binding these scripts to hotkeys.

    to save:
    Code:
    #!/bin/bash
    
    # dump current selection to a file
    xsel -po > "$(date +%F_%T_%N).sel"
    to retrieve:
    Code:
    #!/bin/bash
    
    shopt -s nullglob
    
    # exit if there are no .sel files
    sel=( *.sel )
    if (( ${#sel[@]}==0 )); then exit; fi
    
    # window with contents of files, selection returns the file name 
    z_params="--list --column=file --column=1st-line --hide-header --hide-column=1 --width=500 --height=200"
    s=$( zenity --title="Buffer contents" $z_params < <( for f in *.sel; do echo -e "$f\n$( head -1 "$f" )"; done ) )
    
    # load the selected file to the buffer
    xsel -pi < "$s"
    
    # emulate middle click to paste
    xdotool click 2
    
    # remove selected file
    rm "$s"
    or
    Code:
    #!/bin/bash
    
    shopt -s nullglob
    
    # exit if there are no .sel files
    sel=( *.sel )
    if (( ${#sel[@]}==0 )); then exit; fi
    
    # select first file
    s="${sel[0]}"
    
    # load the selected file to the buffer
    xsel -pi < "$s"
    
    # emulate middle click to paste
    xdotool click 2
    
    # remove selected file
    rm "$s"
    Last edited by Vaphell; September 14th, 2012 at 01:53 AM.
    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
    Feb 2008
    Beans
    Hidden!

    Re: Is there a clipboard manager (or other way) that can do this?

    Quote Originally Posted by Vaphell View Post
    Code:
    #!/bin/bash
    
    shopt -s nullglob
    
    # exit if there are no .sel files
    sel=( *.sel )
    if (( ${#sel[@]}==0 )); then exit; fi
    
    # window with contents of files, selection returns the file name 
    z_params="--list --column=file --column=1st-line --hide-header --hide-column=1 --width=500 --height=200"
    s=$( zenity --title="Buffer contents" $z_params < <( for f in *.sel; do echo -e "$f\n$( head -1 "$f" )"; done ) )
    
    # load the selected file to the buffer
    xsel -pi < "$s"
    
    # emulate middle click to paste
    xdotool click 2
    
    # remove selected file
    rm "$s"
    very clever solution!


  4. #4
    Join Date
    Feb 2010
    Location
    WI USA
    Beans
    9,794
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Is there a clipboard manager (or other way) that can do this?

    Clipit and Parcellite both in the software center if you prefer an application. The script looks like good solution though.
    Infinite diversity in infinite combination.

    Ubuntu Documentation Search: Popular Pages
    Ubuntu: Security Basics
    Ubuntu: Manual

  5. #5
    Join Date
    Sep 2012
    Beans
    6

    Re: Is there a clipboard manager (or other way) that can do this?

    Quote Originally Posted by Vaphell View Post
    it should be rather easy to whip up few short scripts to do something like that, using xsel, xdotool and zenity in case of guification and binding these scripts to hotkeys.
    Thank you very much Vaphell! I didn't know you could write a clipboard manager with such minimal code. Very nice!

    I think I wasn't clear enough in my original post. Thanks to your useful scripts I've got a couple of scripts that do what I want -- they paste in the same order that I copied (so no GUI needed for choosing).

    A couple of notes to anyone who happens across this thread and is interested:
    (1) These don't work perfectly. Sometimes the paste just doesn't paste (and it does pop). I did not find any error. I think the xdotool click was successfully dispatched (return code is 0) so I'm not sure what's going on.

    (2) You will paste into where your mouse is hovering over, not where your cursor is. This is unfortunate but it's exactly this behavior (cleverly thought of by Vaphell) that allows the whole process to work.

    (3) I mapped save.sh to ctrl + alt + c and retrive.sh to ctrl + alt + v. Do what works for you.

    Any critiques of the scripts are welcomed and I will post updates of the scripts on this post in the future if I have reason to. If you think of an alternative implementation, please post your finding.

    save.sh:
    Code:
    #!/bin/bash
    
    storageDir='/tmp/PopPaste'
    
    if [ ! -d "$storageDir" ]; then
      mkdir "$storageDir"
      echo "0" > "$storageDir"/numberSaved
    fi
    
    cd "$storageDir"
    
    if [ -e numberPasted ]; then
      # Once you start pop-pasting, either finish or start over copying again.
      rm numberPasted
      echo "0" > numberSaved
    fi
    
    numSaved=0
    if [ -e numberSaved ]; then
      numSaved=$( cat numberSaved )
    fi
    
    numSaved=$(( $numSaved + 1 ))
    echo $numSaved > numberSaved
    
    # Dump current selection to a file.
    xsel -po > $numSaved
    retrive.sh:
    Code:
    #!/bin/bash
    
    storageDir='/tmp/PopPaste'
    
    if [ ! -d "$storageDir" ]; then
      # save.sh should have created this directory. Are you pasting before copying?
      exit 1
    fi
    
    cd "$storageDir"
    
    numPasted=0
    if [ -e numberPasted ]; then
      numPasted=$( cat numberPasted )
    fi
    
    numPasted=$(( numPasted + 1 ))
    
    if [ ! -e $numPasted ]; then
      # save.sh deleted numPasted if you copied without exhausting clipboard.
      exit 2
    fi
    
    echo $numPasted > numberPasted
    
    xsel -pi < $numPasted
    
    # emulate middle click to paste.
    xdotool click 2
    
    rm $numPasted
    
    onePlus=$(( $numPasted + 1 ))
    if [ ! -e $onePlus ]; then
      # We pasted the last element in the clipboard.
      rm numberSaved
      rm numberPasted
    fi

  6. #6
    Join Date
    Dec 2005
    Location
    Western Australia
    Beans
    11,432
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Is there a clipboard manager (or other way) that can do this?

    This thread just shows how useful Linux is. On Windows you'd need about 2000 lines of C code that touches undocumented APIs; on Ubuntu somebody can whip up a solution for you in Bash in about ten minutes.
    I try to treat the cause, not the symptom. I avoid the terminal in instructions, unless it's easier or necessary. My instructions will work within the Ubuntu system, instead of breaking or subverting it. Those are the three guarantees to the helpee.

  7. #7
    Join Date
    Sep 2012
    Beans
    6

    Re: Is there a clipboard manager (or other way) that can do this?

    Quote Originally Posted by 3rdalbum View Post
    this thread just shows how useful linux is. On windows you'd need about 2000 lines of c code that touches undocumented apis; on ubuntu somebody can whip up a solution for you in bash in about ten minutes.
    +1

Tags for this Thread

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
  •