Wallpaper Database - reset it?

This is a difficult one… As some of you may know I’ve written a wallpaper changer using Apple Shortcuts on the Mac.

It works very well and I’m very pleased with it.

However I’ve run into a macOS issue with it which is caused by the Apple Set Wallpaper shortcut command.

What happens is that when a wallpaper is set it is added to an ‘Wallpaper Desktop Library’’ and the file itself saved in ‘/Users/myuser/Pictures/Shortcuts Desktop Pictures/’

Now I triggered my wallpaper changer every 10 minutes… So that directory contains 26,234 files, taking up over 35Gb of file space.
The macOS Settings app also tries to show them all in the ‘Your Photos’ section of the control.
If you delete those files manually is screws up the ‘Wallpaper Desktop Library’ and it sets a default wallpaper to the desktop and the desktop Wallpaper system breaks.
So the question is, is there a way to prune the photos and update that database even better a way of resetting it?
I’ve searched the web and that references deleting plist files etc. None of those solutions are current for macOS Tahoe.
Any assistance would be appreciated.

I’ve had this suggested:

tell application "System Events"
    repeat with d in desktops
        -- Use a built-in wallpaper path; this one exists on every macOS install
        set picture of d to "/Library/Desktop Pictures/Solid Colors/Stone.png"
    end repeat
end tell

No ideas if itd fix it or make it worse though?

Daron. I don’t know how to reset the Your Photos wallpaper database, but I can suggest a possible workaround, although it requires some preliminary work.

To begin, manually create a custom wallpaper folder at a location and with a name of your choosing. Place a photo–which can later be deleted–in this folder. Then, in System Settings, set this folder as a custom wallpaper folder:

Next, edit your shortcut as follows:

  1. Delete the Set Wallpaper Photo action. Replace it with a Save File action that saves the wallpaper image to the custom wallpaper folder.

  2. Use either Finder or System Events in a Run AppleScript action to set the file created in step 1 as the current wallpaper. The AppleScript needs to be used because it does not create a new file in your ~/Pictures folder.

  3. If desired, delete the prior wallpaper photos in the custom wallpaper folder. As an alternative, you can manually delete the photos periodically.

You could simply skip the custom wallpaper folder part, but then you would have to manually delete wallpapers in System Settings. If the above approach is used, the wallpapers are removed in System Settings if the files are deleted from the custom wallpaper folder. I don’t know why this doesn’t happen with the Your Photos album.

Just as a simple example, the following worked on my Tahoe computer, and this should be able to be incorporated in your shortcut.

Hi Bob, thanks for that. I’ve gone through the steps that you detail and it does work to set the wallpaper without adding any photos into the 'Pictures/Shortcuts Desktop Pictures/’ folder.
But…

  • I may be missing something but after adding the custom wallpaper folder into the ‘Your Photos’ section of the Wallpaper settings I still have it showing the massive amount of wallpapers:

  • After the shortcut has run and finished, the wallpaper change on the desktop doesn’t occur for over 60 seconds. This is one thing I think was caused by the original mess up I made by deleting the prior wallpaper images.
  • The 60 second delay for things to happen also affects other Apps like Hazel whereby copy operations are delayed by that same 60 seconds

Re the OS cleaning up photos in the inbuilt system, I’m not sure if it is intended for it to do so, as I’vs files in there going back to January 27th. That is the day the Mac was last flattened and rebuilt. I think it’s a bug in the OS.

I’ve therefore decided I’ll plan a flatten and rebuild of the Mac, it’ll be a pain but if it resolves the issues I’m suffering and I then switch to the Apple Script wallpaper setting system all should be good.
I’ve already tried an ‘in-place’ reinstall of Tahoe and it didn’t help alas.
Sigh…

Wallpaper configuration is more complicated than it looks because it also ties into the screensaver settings. I tried digging into this a while ago and gave up, so what I’m sharing is basically from the notes I made back then.

The main settings file is here:
/Users/SOME_UID/Library/Containers/com.apple.wallpaper.extension.image/Data/Library/Preferences/com.apple.wallpaper.extension.image.plist

This file is a plist that contains another plist embedded as DATA, so editing it directly is extremely difficult.

Here are the related paths as well:
/Users/SOME_UID/Library/Containers/com.apple.wallpaper.agent
/Users/SOME_UID/Library/Containers/com.apple.wallpaper.extension.image
/Users/SOME_UID/Library/Containers/com.apple.Wallpaper-Settings.extension
/Users/SOME_UID/Library/Containers/com.apple.wallpaper.agent.controls
/Users/SOME_UID/Library/Containers/com.apple.wallpaper.agent.WallpaperIntents
/Users/SOME_UID/Library/Containers/com.apple.settings-intents.WallpaperIntents

/Users/SOME_UID/Library/Preferences/com.apple.Wallpaper-Settings.extension.plist
/Users/SOME_UID/Library/Preferences/com.apple.wallpaper.aerial.plist
/Users/SOME_UID/Library/Preferences/com.apple.wallpaper.plist

/Users/SOME_UID/Library/Application Support/com.apple.desktop
/Users/SOME_UID/Library/Application Support/com.apple.wallpaper

There are two places where caches are stored.
/private/var/folders/TMPID/TMPID/C/com.apple.wallpaper.extension.image

/Users/SOME_UID/Library/Containers/com.apple.wallpaper.agent/Data/Library/Caches/com.apple.wallpaper.caches

This path also contains cache files, but note that the screensaver may also cache data here. If you decide to delete anything, make sure to check what’s inside first.

I hope at least some of this is helpful.

Hells bells… noted for future reference. :slight_smile: Definitely the right decision to go through the pain of a rebuilt instead of wading through that lot :f

Daron. That’s the part I don’t know how to fix. My suggestion should stop that from reoccurring, though.

BTW, in my testing, using the AppleScript to set the wallpaper will not stop the photos from accumulating in the Your Photos album. To stop that, you may have to use a custom wallpaper folder.

Fully understood.
Still very flaky though. The Apple Script is now working maybe 1 in 20 times. Roll on the rebuild! Hopefully I’ll be starting it on the morrow after a lot of backing up etc.

I thought that adding the photos to a custom wallpaper folder would prevent them from being added to the Your Photos album, but, upon retesting, that doesn’t appear to be the case. So, using an AppleScript to set the wallpaper will prevent the images from being saved to the ~/Pictures/Shortcuts Desktop Pictures folder but will not prevent them from accumulating in the Your Photos album. I don’t know how to stop that, other than by manually deleting them in System Settings, which would be a real pain.

Daron. I agree that this is probably a bug.

As a simple test, I manually added two photo files to the Your Photos album by way of System Settings then deleted the source photo files. I would expect the Your Photos entries for these photos to be deleted, but they are still there. I’ll recheck tomorrow to see if they have been deleted.

Unfortunately, your original question–which is how to reset the wallpaper database-remains unresolved (other than manually removing them in System Settings).

A quick update. The Mac is now around 90% commissioned, that is it is usable for me, just none of my niceties in there yet.
So the latest Wallpaper change script using the Apple Script to put the wallpaper in place is now working fully.
I was trying to fudge in a bit using the same file name, but the OS system doesn’t like that and if the file names are the same it doesn’t make the change.
I’ll let it run for a few days and see what happens I guess if I price out those images manually, we’ll see if it causes the issues I had before.
Feeling very happy with the rebuild though. A wallpaper it now put in place in about 5-6 seconds, In the prior Mac build it was taking over 60 seconds.