How could I change the images folder of the screen saver with AS ?

Hello everybody,

The question is in the subject.
I’ve found how to start a screen saver with AS :

tell application “System Events”

    set ss1 to screen saver "Arabesque"
    set ss2 to screen saver "Flurry"
    set ss3 to screen saver "Shell"
    set ss4 to screen saver "iLifeslideshows"
    set ss5 to screen saver "Word of the Day"
    set ss6 to screen saver "iTunes Artwork"
    set ss7 to screen saver "Computer Name"
    set ss8 to screen saver "BOINCSaver"
    start ss3               # (or ss1 or ss2...)

end tell

But that I wish to do, for pictures-based sc savers (like
“iLifeslideshows”), is changing (by AS or shell script) the images
folder.
And also how to change the style of “iLifeslideshows” (origami, mosaic,
pictures wall, floating pictures, Ken Burns, and so on…) ?

JiPaul.

Model: MacBook Pro Retina
AppleScript: 2.4
Browser: Firefox 40.0
Operating System: Mac OS X (10.10)

Hi JiPaul B. Welcome to MacScripter.

I’m afraid I don’t know the answer at the moment, but here’s what I’ve discovered so far, which may help you or someone else here to come up with something that works.

It seems the current iLifeSlideShows settings can be read like this:

-- Display style:
do shell script "defaults -currentHost read com.apple.ScreenSaver.iLifeSlideshows styleKey"
--> "SlidingPanels", "ShiftingTiles", or whatever.

-- Picture folder:
do shell script "defaults -currentHost read com.apple.ScreenSaverPhotoChooser"
-->
"{
    CustomFolderDict =     {
        identifier = \"/Users/me/Desktop/2015_07_06\";
        name = \"2015_07_06\";
    };
    LastViewedPhotoPath = \"/Users/me/Desktop/2015_07_06/JJ Merry Wives 1985.jpg\";
    SelectedFolderPath = \"/Users/me/Desktop/2015_07_06\";
    SelectedSource = 4;
}"
-- SelectedSource = 4 with a custom folder, or 3 with any of the defaults.

The -currentHost option is used because the relevant plist files are in the “ByHost” folder in the user “Preferences” folder.

In theory, it should be possible change, say, the display style to “Origami” like this:

do shell script "defaults -currentHost write com.apple.ScreenSaver.iLifeSlideshows styleKey 'Origami'"

But I haven’t been able to get it to work, even when the screen saver application’s not running. Presumably something else needs to be “killed” to get the setting to take.

Hello Nigel

Somebody smoked the carpet in Cupertino :wink:
The first instruction failed here but what is really funny is that the second one return exactly the same results here on my mac.
Of course, there is no folder “2015_07_06” on my desktop and no file “JJ Merry Wives 1985.jpg” although I searched in the different mounted volumes :wink:

In fact I tested because I wanted to know if /me/ was really returned by the script : it is, or if you edited the results before posting.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 27 septembre 2015 17:31:04

@ Nigel
Hi Nigel, and thanks for your answer.

Actually I’ve found the second instruction except I didn’t know the option -currentHost, which is very useful. I found the correct plist file for the current host and used the exact path to the file, but it’s easier with the option.
And with the first instruction that you gave me, I’ll can find the style. Very well. I knew how to change these parameters with “defaults write”. But, as you say, there is something to kill for these files where read again.

For this I had an answer on an over forum : The process to kill is cfprefsd agent, so the instruction to do is :

killall cfprefsd

(without any sudo)

By the way, I’ve ask here because I thought it was possible directly by Applescript (and now I think it’s not), but my script is a shell script, so I’ve just to put these instructions without the “do shell script”.

Thanks a lot again.

@ Yvan
Hi Yvan,
Sorry to say that but the two instructions work very well here. Actually I think you’ve never been using pictures screen savers
since your last upgrade of Mac OS X. And so you have the default version of the file com.apple.ScreenSaverPhotoChooser.plist where the paths of images and folders where probably the ones used for the tests in Cupertino (and the same for Nigel). And for the first instruction, perhaps the file doesn’t exist before using such pictures screen savers (or before changing the style). So I propose you launch one of these pictures screen savers and try again…

JPaul.

I quite understood the reason of the failure of the first instruction.
I wrote “quite” because for the second instruction, like me, Nigel got the results corresponding to a machine which never used a picture screensaver.

I carefully searched in three boot volumes. There is no file com.apple.ScreenSaverPhotoChooser.plist on them!
As Nigel wrote, the corresponding one is in the Hosts subfolder where it’s not named as you wrote.

In fact, the pref file com.apple.ScreenSaverPhotoChooser.----.plist contains only a descriptor of an empty string.
I reproduce here its entire content :

<?xml version="1.0" encoding="UTF-8"?> LastViewedPhotoPath

So I really don’t know where the shell command find the returned infos.

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 27 septembre 2015 20:30:52

:slight_smile:

Hi Yvan.

As JiPaul B. suggested later, perhaps the plist file doesn’t exist until you change away from the default setting.

Ah. My fault. :lol: In order to get the script to compile, I put the “result” arrow (“–>”) on a different line from my result, which consequently became part of the script code. I’m sure you worked that out. :wink:

“/me/” is indeed a post-edit on my part. “JJ Merry Wives 1985.jpg” is one of a number of scans I did recently of photographs from my former life as a theatre musician.

Thanks Nigel

Now its more clear.

I missed the fact that the → was not in front of your result.
So it’s this one which appeared here.

After removing this artefact, and encapsulating the first instruction in a try block, I got an events log which makes sense :

tell current application
	do shell script "defaults -currentHost read com.apple.ScreenSaver.iLifeSlideshows styleKey"
	(*1*)
	(*2015-09-27 20:48:45.988 defaults[3292:1935529] 
The domain/default pair of (com.apple.ScreenSaver.iLifeSlideshows, styleKey) does not exist*)
	do shell script "defaults -currentHost read com.apple.ScreenSaverPhotoChooser"
end tell
Résultat :
"{
    LastViewedPhotoPath = \"\";
}"

Yvan KOENIG running Yosemite 10.10.5 in French (VALLAURIS, France) dimanche 27 septembre 2015 20:46:59

Hello every body

Actually I’ve had some problem with my script. I think it’s no ok killing cfprefsd agent when the screensaver is activ or when the monitor is sleeping.
So I know how to detect that the ScSav is activ. But how could I know (by script of course) that the monitor is sleeping ? Have you an idea ?

JiPaul.