Change ScreenSaver Via AppleScript

I am trying to make an AppleScriptObjC application that changes your screensaver, I tried using this script but when ScreenSaverEngine launches, it is my default screensaver (not the one that I tried to set it to). Any help is very much appreciated and I am running OS X 10.6.8.

The (failing) script:

set module_path to “~/Library/Screen Savers/Word of the Day.qtz”
set module_name to “Word of the Day”

set myMACaddress to do shell script "/sbin/ifconfig en0 | /usr/bin/awk ‘/ether / {print $2}’ | /usr/bin/tr -d ‘:’ "

do shell script “defaults write ~/Library/Preferences/ByHost/com.apple.screensaver.” & myMACaddress & " moduleName " & quoted form of module_name
do shell script “defaults write ~/Library/Preferences/ByHost/com.apple.screensaver.” & myMACaddress & " modulePath " & quoted form of module_path
tell application id “com.apple.ScreenSaver.Engine” to launch

Model: MacBook Pro
Browser: Firefox 8.0.1
Operating System: Mac OS X (10.6)

Okay, here is the script in the applescript box.

set module_path to "~/Library/Screen Savers/Word of the Day.qtz" 
set module_name to "Word of the Day" 

set myMACaddress to do shell script "/sbin/ifconfig en0 | /usr/bin/awk '/ether / {print $2}' | /usr/bin/tr -d ':' "

do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " moduleName " & quoted form of module_name
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " modulePath " & quoted form of module_path
tell application id "com.apple.ScreenSaver.Engine" to launch

This is a simple Applescript to start or stop the screen saver in OSX 10.6.


tell application "System Events"
	set screen_saver_action to "start" as text --could also be set to "stop"
	set current_screen_saver_name to name of current screen saver --get name of current screen saver
        set installed_screen_savers to the name of every screen saver as list --this gives you a list of every screen saver
	set screen_saver_name to "" as text --put the name of any ibstalled screen saver in this variable
	if screen_saver_action is equal to "start" then
		if screen_saver_name is equal to "" then
			start current screen saver
		else
			if screen saver screen_saver_name exists then
				start (screen saver screen_saver_name)
			else
				display alert "The screen saver named " & screen_saver_name & "does not exist." as informational
			end if
		end if
	else if screen_saver_action is equal to "stop" then
		if screen_saver_name is equal to "" then
			stop current screen saver
		else
			if screen saver screen_saver_name exists then
				stop (screen saver screen_saver_name)
			else
				display alert "The screen saver named " & screen_saver_name & "does not exist." as informational
			end if
		end if
	end if
end tell

This script is only for example purposes, and should be adapted for your needs.

Hope it is of some use to you.

Regards Mark

Ahh, thank you so much! I very much appreciate your response, it has everything I should need to continue my script! If you were wondering though, this is the snippet of code that I was actually looking for:

tell application id "com.apple.systemevents"
set current screen saver to screen saver named "(screen saver name here!)"
end tell

I was very confused by all the POSIX paths, Property Lists, and other stuff that I didn’t think of the obvious! My best appreciation!

TechExpertHD :slight_smile: