Last active
February 21, 2026 05:48
-
-
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接受管道输入)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
satty is a wayland annotation tools: Satty-org/Satty#118 (comment)
satty-pin.sh: