use framework "Foundation"
use scripting additions
property picturesFolder : POSIX path of (path to pictures folder)
property picturesNighttime : {picturesFolder & "DSC_0004_2.JPG"}
property picturesDaytime : {picturesFolder & "DSC_0034.JPG", picturesFolder & "Rainy_Blue_Ridge-27527.jpg"}
my themeChanged:(missing value)
tell current application's NSDistributedNotificationCenter's defaultCenter to addObserver:me selector:"themeChanged:" |name|:"AppleInterfaceThemeChangedNotification" object:(missing value)
on themeChanged:theNotification
try
tell application "System Events" to tell appearance preferences
set {newColor, desktopPictures} to {blue, picturesDaytime}
if dark mode then set {newColor, desktopPictures} to {graphite, picturesNighttime}
set {highlight color, appearance} to {newColor, newColor}
end tell
tell application "System Events" to tell the first desktop to set picture to some item of the desktopPictures
end try
end themeChanged:
on quit
tell current application's NSDistributedNotificationCenter's defaultCenter to removeObserver:me
continue quit
end quit