Set screensaver

Hello all,

Is it possible to set the current screensaver with AppleScript? I am trying to install and set the current screensaver without using a third party app like screenweaver.

Thank you,
eDdie

I think he wants to change the screensaver display.

Also, for future reference, a shell script is not required to start the screensaver, this line will do it (at least in Tiger):

activate application "ScreenSaverEngine"

If you mean you want to switch Screen Saver modules with only a script, eDdie, then that’s certainly possible.

However, since I’m not totally clear about the context of your question, I can offer only a general demonstration - and the following script may therefore be more than you require for your specific purposes. You may be able to glean what you need from the example but, if you’d like help with a simpler approach, perhaps you could fill in a little more detail about what you’re trying to do… :slight_smile:

to getPrefsFile at p given slideshow:s
	tell application "System Events"
		if s then return property list file ((folder p's first file whose name ¬
			starts with "com.apple.screensaver.slideshow.")'s POSIX path)
		property list file ((folder p's first file where name starts with ¬
			"com.apple.screensaver." and "slideshow" is not in name)'s POSIX path)
	end tell
end getPrefsFile

to chooseModule(v)
	set {f, r, q} to {(path to "dlib" from system domain)'s POSIX path & ¬
		"Screen Savers/", {}, {"Pictures Folder", "Choose Folder."}}
	tell application "Finder" to set l to (name of folder (my POSIX file f)'s ¬
		document files whose kind starts with "Mac OS X Preference Screen") & q
	repeat with i in l
		set r's end to i's text 1 thru ((offset of "." in i) - 1)
	end repeat
	set {d, text item delimiters} to {text item delimiters, return}
	set {r, text item delimiters} to {r as string, d}
	set i to (choose from list r's paragraphs with prompt "Choose a Screen Saver module:" default items v)
	if i is false then error number -128
	set i to i's item 1
	if i is not in q then return {i, f & l's item (count paragraphs of r's text 1 thru (offset of (i & return) in (r & return)))}
	set p to POSIX path of (POSIX file ((path to "fram")'s POSIX path & ¬
		"ScreenSaver.framework/ScreenSaver") as Unicode text)
	if i is "Pictures Folder" then return {i, p, (path to "pdoc")'s POSIX path}
	{i, p, (choose folder with prompt "Choose a pictures folder:")'s POSIX path}
end chooseModule

set prefsFolder to (path to "pref")'s POSIX path & "ByHost/"
set prefsFile to getPrefsFile at prefsFolder without slideshow
tell application "System Events"
	tell prefsFile to set currName to property list item "moduleName"'s value
	set moduleData to my chooseModule(currName)
	if exists process "System Preferences" then quit application "System Preferences" (* precaution *)
	tell prefsFile to set {property list item "moduleName"'s value, property list item "modulePath"'s value} to moduleData
	if (count moduleData) is 3 then tell my (getPrefsFile at prefsFolder with slideshow) ¬
		to set property list item "SlideFolder"'s value to moduleData's item 3
end tell
launch application "ScreenSaverEngine" (* demonstrate result *)

Thank you for all the informative answers. To clear up what I am trying to do. I have a Macromedia director application that has a feature of displaying information through your screensaver and desktop. Like any good multimedia project the software is for MAC and PC.

For the PC version I have an exe/scr file in a local folder and through my application I can set the saver path and current screensaver through xtras in director but for most xtras these are PC only feature. So my idea is to use an Xtra in director zScript http://www.zeusprod.com/ that gives you access to AppleScript calls to assign the current screensaver.

Thank you again, you guys have been great. I never expected AppleScript to be so robust.

eDdie