looking for simple clipboard monitoring solution

Discussion in 'Mac OS X Lion (10.7)' started by nycaleksey, Feb 23, 2012.

  1. nycaleksey macrumors member

    nycaleksey

    Joined:
    Jul 14, 2009
    #1
    Hi,

    I have been trying to find an OS X tool for one specific task and couldn't find it. I need to have a program running in the background and monitoring clipboard. When the contents of the clipboard matches certain regexp it should execute a script with the contents of clipboard being passed on as a parameter.

    There's tons of clipboard managers both free and not, but none seems to have this exact type of functionality. Can someone suggest a tool or a possible solution that doesn't involve system programming? Maybe it is achievable with higher level tools like shell scripts, launchd, applescript or automator?

    Thank you.
     
  2. nycaleksey, Feb 23, 2012
    Last edited: Feb 28, 2012

    nycaleksey thread starter macrumors member

    nycaleksey

    Joined:
    Jul 14, 2009
    #2
    It's funny how they are right when saying - one has to know half of the answer to ask the right question. Posting this message and mentioning shell scripts got me thinking, and 10 minutes later the shell script solution for my problem has been created. Here it is:

    #!/bin/bash

    while :
    do
    clipboard=`pbpaste`
    if [[ "$clipboard" =~ <mypattern> ]]
    then
    <myscript.sh> $clipboard
    pbcopy < /dev/null
    fi
    sleep 1
    done

    This is crude but does the task and doesn't eat too much resources.

    If anyone knows of a cleaner way to accomplish this or an existing software solution please let me know.
     

Share This Page