I’ve three screens on a Mac mini m4 v 15.1 with the next configuration:
I attempted to alter wallpaper by way of AppleScript on a multi-monitor setup (no error, no change)
osascript -e 'inform software "System Occasions" to set image of desktop 1 to POSIX file "/Customers/jdoe/Desktop/wallpapers/DSC01990.JPG"'
enter code right here
It returns immediately with no error, however the wallpaper by no means modifications.
Terminal has Full Disk Entry, Automation permissions for System Occasions are enabled, and the picture path is legitimate. Desktop rely returns 3 appropriately. The whole lot else works besides setting the wallpaper.
Is wallpaper scripting deprecated? Is there a working technique to set wallpaper programmatically on macOS with a number of shows?
My whole Node.js code:
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const WALLPAPER_DIR = "/Volumes/4TB/Pictures/wallpapers";
const allFiles = fs.readdirSync(WALLPAPER_DIR).filter(f => /.(jpg|jpeg|png|heic)$/i.check(f));
if (allFiles.size === 0) {
console.error("No wallpapers discovered.");
course of.exit(1);
}
perform shuffle(arr) {
return arr.type(() => Math.random() - 0.5);
}
// Choose 3 random pictures
const chosen = shuffle(allFiles).slice(0, 3);
console.log("Chosen wallpapers:");
chosen.forEach((f, i) => {
console.log(`Monitor ${i + 1}: ${f}`);
});
// Convert to absolute paths (escaped)
const abs = chosen.map(f => path.be a part of(WALLPAPER_DIR, f).substitute(/"/g, '"'));
// Construct AppleScript
// Vital: backticks inside a template literal are escaped
const script = `
inform software "System Occasions"
set desktopCount to rely of desktops
repeat with i from 1 to desktopCount
set thePath to "${abs[0]}"
if i = 2 then set thePath to "${abs[1]}"
if i = 3 then set thePath to "${abs[2]}"
set image of desktop i to thePath
finish repeat
finish inform
`;
// Run AppleScript
execSync(`osascript <<EOF
${script}
EOF`);
console.log("Wallpapers up to date.");

