xclip 在图片文件大小过大时不工作

Last

问题描述

  • 先前的一篇博文中,我使用 maim 代替了 flameshot 作为截图软件,并且设置了相应的快捷键:
1
2
3
4
5
6
7
# screenshot to clipboard
ctrl + alt + a
maim --select | xclip -selection clipboard -target image/png

# screenshot to file
ctrl + alt + s
maim --select ~/Pictures/screenshot/$(date +%Y-%m-%d_%H-%M-%S_maim | tr A-Z a-z).png
  • 然而,我发现每当我想要截取整个屏幕范围并使用 xclip 复制到他处时,不是无法粘贴就是直接卡死。
  • 经查询得知,这是因为 xclip 没有对于图片文件的支持,导致其在复制图片时会直接将所有的图片数据保存在系统剪贴板中。当图片文件过大时就会引发问题。

解决方案

  • 参照该 issue ,解决方案的思路是将图片文件保存在 /tmp/img.png ,xclip 仅仅复制图片文件的链接。

  • 修改快捷键:

1
2
3
4
# screenshot to clipboard
ctrl + alt + a
maim -su -b 2 /tmp/img.png; \
echo "file:///tmp/img.png" | xclip -selection clipboard -target text/uri-list
  • 顺便加上 dunst 提示:
1
2
3
4
5
6
7
8
9
10
11
# screenshot to clipboard
ctrl + alt + a
maim -su -b 2 /tmp/img.png; \
echo "file:///tmp/img.png" | xclip -selection clipboard -target text/uri-list; \
notify-send -u low -t 3000 "Screenshot copied to clipboard"

# screenshot to file
ctrl + alt + s
filename=`date +%Y-%m-%d_%H-%M-%S_maim | tr A-Z a-z`; \
maim -su -b 2 ~/Pictures/screenshot/$filename.png; \
notify-send -u normal -t 3000 -i ~/Pictures/screenshot/$filename.png "Screenshot taken"
  • Title: xclip 在图片文件大小过大时不工作
  • Author: Last
  • Created at : 2023-08-27 21:40:17
  • Link: https://blog.imlast.top/2023/08/27/xclip-disfunction-when-image-size-too-large/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
xclip 在图片文件大小过大时不工作