How do you change Screesaver folder with command line on Mac

I have an art collection of 8000 pics, I have them divided into folders of about 200 each. I'm going to use python to randomly select one of these folders so that my screensaver will continually show me the work of a new artist rather than randomly mixing all the artists together. To do this I need to change the folder that the screensaver uses with Python which will then change the folder using Terminal.

I read this article and it seems that you can do that by using this command:

https://krypted.com/mac-security/mac-setting-screen-saver-from-the-cli/

defaults -currentHost write com.apple.screensaver modulePath -string "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/"

But that didn't work. Also, I am using macos 10.14

UPDATE

When I input: /usr/bin/defaults -currentHost read com.apple.ScreenSaverPhotoChooser I get the expected result, viz, the actual folder that the screensaver is using. When I input: /usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser SelectedFolderPath -string "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/" then input /usr/bin/defaults -currentHost read com.apple.ScreenSaverPhotoChooser I get

{
    CustomFolderDict =     {
        identifier = "/Users/kylefoley/Pictures/art/complete art 2";
        name = "complete art 2";
    };
    SelectedFolderPath = "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/";
    SelectedSource = 4;
    ShufflesPhotos = 1;
}

Which is wrong because the path for the CustomFolderDict['identifier'] should be the same as the SelectedFolderPath

I then made a guess and tried:

/usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser CustomFolderDict -identifier "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/"

which outputted Unexpected argument. If think I could figure out how to fix that CustomFolderDict with command line then that might solve the problem.

UPDATE 2

I inputted:

/usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser CustomFolderDict -dict-add identifier "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/"
/usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser CustomFolderDict -dict-add name "claude monet"

And although I get

{
    CustomFolderDict =     {
        identifier = "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/";
        name = "claude monet";
    };
    LastViewedPhotoPath = "";
    SelectedFolderPath = "/users/kylefoley/pictures/art/art 2/impressionism/claude monet/";
    SelectedSource = 3;
    ShufflesPhotos = 1;
}

When I input

/usr/bin/defaults -currentHost read com.apple.ScreenSaverPhotoChooser

The new result is just a blank screen with the name of my computer on it.


Solution 1:

This works for me on a Catalina machine and is known to work on Mavericks (HT @bobsmith76 for persevering).

/usr/bin/defaults -currentHost write com.apple.ScreenSaverPhotoChooser 'SelectedFolderPath' "/Users/you/sub/sub/folder"

I used hot-corners to turn on the screen saver, and set different default, then when I enabled screen saver again it used the new folder.

NOTE if you have System Preferences open when making the changes then this may cause the wrong thing to happen (like the screensaver config flipping to a non-image screensaver - we both ended up on the Message screensaver this way).