Introduction
The way question is posted, requires more than just having a simple script, but also a GUI interface for enabling/disabling the script. I've found that it would be easier to achieve via an Application Indicator that would be accessible from Ubuntu's top panel. This answer presents exactly that as a solution.
The clipboard-autoedit-indicator
, which I've written specifically for this question, allows for automatic editing of clipboard contents based on a regex expression ( choice of sed
or python's re
style ). It uses Gtk's clipboard module and minimum dependencies, thus no need for installing additional tools such as xclip
or xsel
.
Installation
Run the following commands in terminal:
sudo add-apt-repository ppa:1047481448-2/sergkolo
sudo apt-get update
sudo apt-get install clipboard-autoedit-indicator
Usage
The indicator can be launched by typing in Unity Dash Clipboard Autoedit
or via calling /usr/bin/clipboard-autoedit-indicator
from command-line. There are two indicator icons (colored and grayed-out clipboard icon) to display when dynamic editing of the clipboard is enabled/disabled. When editing occurs, notification is sent to the user.

The "Set regex pattern" menu item calls zenity
forms dialog. When user edits regex rule, it is remembered and stored in ~/.clipboard-autoedit-config.json
file. The dynamic editing will be enabled automatically when user clicks OK button, but users can disable it via "Replacement Enabled" check menu item. The regex type defaults to python's re
module.

Source code
The source code is available under the MIT license on GitHub. Further development and newer versions will be there, and if you have a feature request and/or bug report, please submit them on GitHub.