问题描述
我想读取一个文本文件的内容,将其复制到剪贴板(如果它不为空),然后粘贴到鼠标光标所在的 gedit
窗口。
这是我的脚本:
while true
do
if [ -s textfile ]
then
cat textfile | xclip -selection clipboard
xdotool key --clearmodifiers Control_L+v
truncate -s 0 textfile
fi
done
除xdotool
外的所有作品:
- 如果我手动按下 CTRL+v,它会正确粘贴。
- 如果我运行 xev,我可以看到 xdotool 发送了正确的键盘事件,但没有任何反应。
我尝试了一些其他命令,例如:
xdotool key ctrl+v
xdotool type $(xclip -selection clipboard -o)
-
xdotool getactivewindow type $(xclip -selection clipboard -o)
,这给了我错误XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1)
sleep 1 && xdotool key Control_L+v
没运气。
有人可以帮我吗?
解决方法
这对我有用:
xdotool type "$(xclip -o)"
,
我解决了,问题是缺少 Libx11-dev。安装库后,脚本即可正常工作。