Skip to content

Instantly share code, notes, and snippets.

@AClon314
Last active February 21, 2026 05:48
Show Gist options
  • Select an option

  • Save AClon314/08d37adc2d31dc008aa9f9f9001e0fd1 to your computer and use it in GitHub Desktop.

Select an option

Save AClon314/08d37adc2d31dc008aa9f9f9001e0fd1 to your computer and use it in GitHub Desktop.
From the latest N records of copyq, output the binary buffer of the latest image to stdout (convenient for satty to accept pipeline input) 从copyq最近N条记录中,输出最新图片的二进制buffer到stdout(方便satty接受管道输入)
const recent = 10;
const maxMB = 10;
for (i = 0; i < Math.min(recent, size()); ++i) {
const mimes = str(read("?", i))
.split("\n")
.filter((v) => v.startsWith("image/"));
// .filter((v) => v.startsWith("image/") || v == "text/plain");
for (const m of mimes) {
const bin = read(m, i);
if (m == "text/plain") {
const string = str(bin);
const path = (
decodeURIComponent(string.match(/file:\/\/(.*)/)?.[1] || "") || string
).trim();
// print(`path: ${m} ${path}\n`);
// 保证绝对路径,且以/开头
if (path.startsWith("/")) {
print(path);
abort();
}
} else {
// print(`bin: ${m} ${bin.length}\n`);
// 防止大文件卡死
if (bin.length < maxMB * 40960) {
print(bin);
}
abort();
}
}
}
@AClon314
Copy link
Author

satty is a wayland annotation tools: Satty-org/Satty#118 (comment)

satty-pin.sh:

#!/bin/bash
SATTY="/home/n/bin/satty"
copyq_pic() {
    cat copyq-paste-photo.js | copyq eval -
}
copyq_pic | "$SATTY" --filename - "$@"

# MIME=$(copyq_pic | file -b -)
# # echo "检测到数据类型:$MIME"
# if echo "$MIME" | grep -q "text"; then
#     "$SATTY" --filename "$(copyq_pic)" "$@"
# else
#     copyq_pic | "$SATTY" --filename - "$@"
# fi

# env GTK_DEBUG=interactive
# wl-paste | /home/n/bin/satty --filename - $@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment