Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nycaleksey

macrumors member
Original poster
Jul 14, 2009
63
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.
 

nycaleksey

macrumors member
Original poster
Jul 14, 2009
63
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.

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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.