Files
python/VsCode配置/Other/WatchClip.py
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
import sys
import os
import re
# pip3 install install pyperclip
sys.path.append(os.path.abspath("SO_site-packages"))
import pyperclip # 引入模块
recent_value = ""
tmp_value = "" # 初始化应该也可以没有这一行感觉意义不大。但是对recent_value的初始化是必须的
while True:
tmp_value = pyperclip.paste() # 读取剪切板复制的内容
if tmp_value != recent_value: # 如果检测到剪切板内容有改动,那么就进入文本的修改
recent_value = tmp_value
lines = recent_value.split('\r\n')
changed = "\"Title\":{\"prefix\":\"ActionName\",\"body\": ["
cnt=0
for line in lines:
line = line.replace('"', '\\"')
line = '"' + line + '"'
cnt=cnt+1
if cnt>1:
changed = changed + ',\r\n' + line # 将文本的换行符去掉,变成一个空格
else:
changed = changed + '\r\n' + line # 将文本的换行符去掉,变成一个空格
changed =changed+"]},"
recent_value = changed
pyperclip.copy(changed) # 将修改后的文本写入系统剪切板中
print("\n Value changed: %s" % str(changed)) # 输出已经去除换行符的文本
time.sleep(0.1)