This forum has been archived. All content is frozen. Please use KDE Discuss instead.

how to automatically edit text in clipboard

Tags: None
(comma "," separated)
User avatar
RazrFalcon
Registered Member
Posts
23
Karma
0
OS
I need something like Klipper's actions, but fully automatic.

For example, it must remove file://, from clipboard, add paste text without it.

Before: file:///home/user/text.txt
After: /home/user/text.txt

Thanks.
john_hudson
Registered Member
Posts
549
Karma
2
OS
This is more in the nature of a wish but I am not sure that it is practicable - how would the software know when you wanted to edit and when you did not? The easiest way to truncate something like that is to highlight what you want fist and then copy it. Or can you be more specific about what you want done automatically?


John Hudson, proud to be a member of KDE forums since 2008-Oct.
User avatar
RazrFalcon
Registered Member
Posts
23
Karma
0
OS
It must replace text always.
Something like this:
Code: Select all
#!/bin/bash
clip="`qdbus org.kde.klipper /klipper  org.kde.klipper.klipper.getClipboardContents`"
clip_new="`echo "$clip" | sed 's/file:\/\///g'`"
qdbus org.kde.klipper /klipper  org.kde.klipper.klipper.setClipboardContents "$clip_new"

But it didn't work. Because Klipper didn't have signal like newContentsAdded().
tthiasoss
Registered Member
Posts
6
Karma
0
OS
RazrFalcon wrote:But it didn't work. Because Klipper didn't have signal like newContentsAdded().


Can't you add your script as a new action to Klipper?
alexs77
Registered Member
Posts
3
Karma
0
OS
I'm also looking for a way to do this. In my case, I'd like to have "shortcuts" which should allow me to insert text I use often quickly.

Eg. I'm tired of typing "Sehr geehrte Damen und Herren," and look for a faster way.

I came up with a script (also below) which looks up a "short code" (eg. "SgDuH") in a "database" and gets the long version.

The script works just fine, but how do I make Klipper execute the script automatically, if I eg. add the text "SgDuH" to the clipboard?

My Klipper settings:

Image

But it seems like my script isn't called at all (in the real script, I've got some logging and this log isn't created).


================

Update:

Okay, it helps quite a bit, to actually ENABLE these actions ;)

It works quite well - but only, if I'm in Kate (or Qt/KDE apps in general?). It does not seem to work, when I copy some text from eg. Firefox. It also works in Chromium.

In Kate/Chromium, when I copy the SgDuH text, a popup is shown and I can run my custom action script.

Image


===============

Update #2:

I worked a bit on it and got it to work! → http://esisteinfehleraufgetreten.wordpr ... e-klipper/

WARNING!
BUT … it doesn't work so well


:'( After I removed the exclusion rule for Netscape / Firefox from the Klipper configuration, my action started to fire. Nice!
But not only MY action started to fire, but also default rules for eg. highlighting "http://Foo.Bar/". Because of that, there's a whole lot of popups like this being shown:

Image

Ie. when a text starting with "http://" is highlighted (eg. in the address bar…), a popup shows.

Not so good.

Is there a way to forbid THESE popups (for http:// and the like) just for Firefox (and Chrome, Opera, …)? This popup is good and wanted for Konsole, Kate and others, though.

===============

Scripts:

Code: Select all
#! /bin/bash

# Ersetze den übergebenen Text aus der Zwischenablage mit
# einem neuen Text.
# Bsp.: Mache aus "SgDuH" "Sehr geehrte Damen und Herren"

replace_db="$HOME/var/klipper-replace-text.txt"

# Holen:
# qdbus org.kde.klipper /klipper  org.kde.klipper.klipper.getClipboardContents
# Setzen:
# qdbus org.kde.klipper /klipper  org.kde.klipper.klipper.setClipboardContents Klipper-Replace-Text

# Hole Text aus der Zwischenablage
clip=$( qdbus org.kde.klipper /klipper org.kde.klipper.klipper.getClipboardContents )
clip_quoted=$( printf "%q" "$clip" )

# Suche in der "DatenbanK"
replace=$( awk -F'°' "/^${clip_quoted}/ "'{print $2}' "$replace_db" 2> /dev/null )

# Was gefunden?
[[ -z "$replace" ]] && exit 1

# Expandiere evtl. vorhandene Backslash Sequenzen (\n -> Zeilenumbruch)
replace_bs=$( printf "%b" "$replace" )

# Speichere in Zwischenablage
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents "$replace_bs" > /dev/null 2>&1
printf "%s\n" "$replace_bs"

exit $?
# EOF #


Code: Select all
SgDuH°Sehr geehrte Damen und Herren,
SgK°Sehr geehrte Kundin,\nSehr geehrter Kunde,
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Unfortunately it seems that Klipper does not allow for actions to be disabled depending on the window currently in use - it only allows for all actions to be disabled.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]