小编Sid*_*Man的帖子

检测剪贴板复制/粘贴事件并修改剪贴板内容

将某些内容复制到剪贴板(使用 ctrl+c)后,我想要一个脚本(bash、python 或任何其他语言)自动检测新条目已添加到剪贴板,更改其内容并将其放回剪贴板,以便在粘贴时我得到修改后的文本。该脚本应不断在后台运行并监视剪贴板的变化。

以下脚本描述了所需的修改:
来源:https : //superuser.com/questions/796292/is-there-an-efficient-way-to-copy-text-from-a-pdf-without-the-换行

#!/bin/bash

# title: copy_without_linebreaks
# author: Glutanimate (github.com/glutanimate)
# license: MIT license

# Parses currently selected text and removes 
# newlines that aren't preceded by a full stop

SelectedText="$(xsel)"

ModifiedText="$(echo "$SelectedText" | \
    sed 's/\.$/.|/g' | sed 's/^\s*$/|/g' | tr '\n' ' ' | tr '|' '\n')"

#   - first sed command: replace end-of-line full stops with '|' delimiter and keep original periods.
#   - second sed command: replace empty lines with …
Run Code Online (Sandbox Code Playgroud)

bash scripts clipboard xclip xsel

9
推荐指数
1
解决办法
3813
查看次数

标签 统计

bash ×1

clipboard ×1

scripts ×1

xclip ×1

xsel ×1