Screensaver Swap with AppleScript

We’re running OSX 10.2 on an old G4 that is providing content to a plasma screen, advertising various projects that we’re working on. We use the Apple Screensaver, selecting a pictures folder that cycles through the pictures.

We have four programs, and want to change from one to another every hour on the hour. I’m using the following script to acheive this:

tell application “Finder”
activate
set name of folder “active” of folder “Desktop” of folder “will” of folder “Users” of startup disk to “inactive”
set name of folder “set 1” of folder “Desktop” of folder “will” of folder “Users” of startup disk to “active”
set name of folder “set 2” of folder “Desktop” of folder “will” of folder “Users” of startup disk to “set 1”
set name of folder “set 3” of folder “Desktop” of folder “will” of folder “Users” of startup disk to “set 2”
set name of folder “inactive” of folder “Desktop” of folder “will” of folder “Users” of startup disk to “set 3”
end tell

The slides for the four programs are contained in folders named active, set 1, set 2, and set3.

This is working well enough. I saved the script as an application and call that application every hour using iCal. The application, thankfully, doesn’t wake the computer from screensaving.

The problem I’ve run into is that the screensaver seems to get stuck where it was during the change. Following the change, the screensaver will only display the last two slides it showed form the previous program, and it repeats those two slides until it wakes.

Anyone know of a good workaround? I’m thinking I might wake and then restart the screensaver immediately following each folder swap. But I’m not sure how to do this. I tried

tell application “ScreenSaverEngine” to deactivate
end tell
tell application “ScreenSaverEngine” to activate
end tell

to see if it might do the job (I don’t think deactivate is valid applescript, however). But I couldn’t compile the script, because the system (and I) couldn’t find the ScreenSaverEngine application, and it required me to locate it. I also don’t know if this will work, because we require a password on wake…

Any ideas? Any ideas for a different approach?

Thanks, and apologies for being so ignorant in advance,

Will

Here’s where you can find the ScreenSaverEngine:

tell application “Finder”
activate
make new Finder window to startup disk
set target of Finder window 1 to folder “Resources” of folder “A” of folder “Versions” of folder “ScreenSaver.framework” of folder “Frameworks” of folder “Library” of folder “System” of startup disk
end tell

Hi Will,

I don’t think your script would work, because it should error when renaming your folders. iCal is probably not warning you of this.

Anyway, your theory seems like it should work, but it probably won’t because the system remembers what folder to use even if you change the names I think.

What I would do is don’t do anything with the selected folder, but change its contents. The following script uses 2 folders, “SS Pictures” and “Current Pictures”. “SS Pictures” contains folders of pictures. “Current Pictures” is empty at the beginning and this is where the script places alias’ of folders from “SS Pictures”. “Current Pictures” is the folder that you select as your screen saver folder. What the script does is swap out alias’ of different folders from “SS Pictures” to “Current Pictures”

set dp to (path to desktop) as string
set ss_pictures to (dp & “SS Pictures”) as alias
set cur_pictures to (dp & “Current Pictures”) as alias
tell application “Finder”
set folder_list to every folder of pic_folder
end tell
repeat with this_folder in folder_list
tell application “Finder”
delete every file of cur_pictures – clear the folder
make alias to this_folder at cur_pictures
end tell
tell application “ScreenSaverEngine” to activate
delay 60
end repeat

gl,

Hi,

So I was thinking that the easiest way to run the script from iCal is to use an index to keep track of which folder was last used and to delete all items in the cur_pictures folder. Something like this should work:

property i : 0
property ss_pictures : “Macintosh HD:Users:kel:Desktop:SS Pictures:”
property cur_pictures : “Macintosh HD:Users:kel:Desktop:Current Pictures:”

try
set ss_pictures to ss_pictures as alias
set cur_pictures to cur_pictures as alias
on error – some folder is missing
beep 2
return
end try
tell application “Finder”
set folder_list to (every folder of ss_pictures)
end tell
set c to (count folder_list)
set i to (i mod c) + 1
set the_folder to (item i of folder_list)
tell application “Finder”
delete every item of cur_pictures
make alias file to the_folder at cur_pictures
end tell
try
tell application “ScreenSaverEngine” to activate
on error
display dialog “Try again.”
end try

gl,

Thanks everyone for the help. Using some of your ideas, kel, I devised the following script:

tell application “Finder”
activate
set active to “The Will:Users:will:Desktop:active” as alias
set set1 to “The Will:Users:will:Desktop:set1” as alias
set set2 to “The Will:Users:will:Desktop:set2” as alias
set set3 to “The Will:Users:will:Desktop:set3” as alias
set temp to “The Will:Users:will:Desktop:temp” as alias
end tell

tell application “Finder”
move every file of active to temp
move every file of set1 to active
move every file of set2 to set1
move every file of set3 to set2
move every file of temp to set3
end tell

But I have the same problem… after the script runs in the background, the screensaver is still stuck between two images that it oscilates between until it wakes.

I’m thinking that it needs to wake, and be put to sleep.

I know that

tell application “ScreenSaverEngine”
activate
end tell

will start the screensaver. But how can I wake the system? We have it password protected, will I need it to enter the password in the script?

Thanks again everyone for your help, already given and yet to be received, and apologies once more for being so ignorant.

Will