2023-02-26 10:59:03 +00:00
|
|
|
import { Command } from "https://deno.land/x/cliffy@v0.25.7/command/mod.ts";
|
2022-12-13 14:03:00 +00:00
|
|
|
|
|
|
|
const imagePath = new URL("../data/wallpaper.jpg", import.meta.url).pathname;
|
|
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
|
const { options } = await new Command()
|
|
|
|
.name("desktop-wallpaper")
|
|
|
|
.description("Desktop wallpaper changer for XFCE")
|
|
|
|
.option("--unsplash", "Download a random Unsplash wallpaper")
|
|
|
|
.option("--height <height:number>", "The height of the image", {
|
|
|
|
default: 1080,
|
|
|
|
depends: ["unsplash"],
|
|
|
|
})
|
2023-01-28 15:04:17 +00:00
|
|
|
.option(
|
|
|
|
"--save-current <file:file>",
|
|
|
|
"Save the current wallpaper to a different file",
|
|
|
|
)
|
2023-01-29 12:28:02 +00:00
|
|
|
.option("--set <file:file>", "Set a file as the wallpaper")
|
2022-12-13 14:03:00 +00:00
|
|
|
.option("--width <width:number>", "The width of the image", {
|
|
|
|
default: 1920,
|
|
|
|
depends: ["unsplash"],
|
|
|
|
})
|
|
|
|
.parse(Deno.args);
|
|
|
|
|
2023-01-28 15:04:17 +00:00
|
|
|
if (options.saveCurrent) {
|
|
|
|
await Deno.copyFile(imagePath, options.saveCurrent);
|
|
|
|
}
|
|
|
|
|
2023-01-29 12:28:02 +00:00
|
|
|
if (options.set) {
|
|
|
|
await setWallpaper(options.set);
|
|
|
|
}
|
|
|
|
|
2022-12-13 14:03:00 +00:00
|
|
|
if (options.unsplash) {
|
|
|
|
await downloadImage(
|
|
|
|
`https://source.unsplash.com/random/${options.width}x${options.height}`,
|
|
|
|
);
|
|
|
|
console.log("Saved Unsplash image to");
|
|
|
|
console.log("-", imagePath);
|
|
|
|
await setWallpaper();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function downloadImage(url: string): Promise<void> {
|
|
|
|
await Deno.run({
|
|
|
|
cmd: ["curl", "-fsLS", url, "-o", imagePath],
|
|
|
|
}).status();
|
|
|
|
}
|
|
|
|
|
2023-01-29 12:28:02 +00:00
|
|
|
async function setWallpaper(file: string = imagePath): Promise<void> {
|
2022-12-13 14:03:00 +00:00
|
|
|
const monitors = ["monitorHDMI-0", "monitorHDMI-1"];
|
|
|
|
for (const monitor of monitors) {
|
|
|
|
await Deno.run({
|
|
|
|
cmd: [
|
|
|
|
"xfconf-query",
|
|
|
|
"-c",
|
|
|
|
"xfce4-desktop",
|
|
|
|
"-p",
|
|
|
|
`/backdrop/screen0/${monitor}/workspace0/last-image`,
|
|
|
|
"-s",
|
2023-01-29 12:28:02 +00:00
|
|
|
file,
|
2022-12-13 14:03:00 +00:00
|
|
|
],
|
|
|
|
}).status();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (import.meta.main) {
|
|
|
|
void main();
|
|
|
|
}
|