Applescript to change screen saver

Posted:
in Genius Bar edited January 2014
At night, i tend to use my mac for watching tv shows/movies and often fall asleep in front of it. However when the video has finished the bright desktop or sometimes my itunes artwork screensaver manages to wake me up - pretty annoying.



Does anyone know how to write an applescript that i can run before going to bed which will automatically change the deafult time of my screensaver to 3 minutes and change my screensaver to a pre-made black picture (i.e. to blank out the screen before the monitor sleeps after the smallest amount of time possoble) to stop me having to manually perfrom this procedure every night. I really want to write the script but have no idea where to start so any pointers would be greatfully accepted.



Cheers

Comments

  • Reply 1 of 6
    lundylundy Posts: 4,466member
    Here is a script that will change the interval to 3 minutes and change the screensaver to the "Computer Name" screensaver, which is mostly black.



    Thanks to the famous Kai of Kai's Applescripts for the inspiration.



    Select all the text in the quote block below, choose "Make New AppleScript" from Safari's Safari->Services->Script Editor menu, and then switch to Script Editor and save it as an application. Put it in the Dock and click it whenever you want to change the screensaver settings to these settings.



    Quote:

    set prefsFolder to (path to "pref")'s POSIX path & "ByHost/"

    tell application "System Events"

    \tset prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.apple.screensaver.")'s POSIX path)

    \ttell prefsFile

    \t\tset value of property list item "moduleName" to "Computer Name"

    \t\tset value of property list item "idleTIme" to 180

    \t\tset value of property list item "modulePath" to "/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver"

    \tend tell

    \tif exists process "System Preferences" then quit application "System Preferences"

    end tell



  • Reply 2 of 6
    Hey - gimmie a chance.



    Your last post was incredibly useful, I've created the application. I was just trying to find out a little more before i responded with a followig question. As i said i am an applescript novice but capable enough to take what you supplied and edit it to create a custom script, the new one i am trying to create would involve switching the screen saver back to the iTunes artwork screen saver, but i do not know where it is found in Finder, i can only find the .plist file.



    Also is there any way to change the brightness of the screen using applescripts?



    Thanks for your last post, i just hadn't had a chance to respond yet
  • Reply 3 of 6
    lundylundy Posts: 4,466member
    Heh - sorry I was so impatient. I just had like 12 scripts in a row where nobody came back ..



    To change the script so that it reverts to the iTunes Artwork screensaver, here are the values that you need to put into the 3 "set value of property list item" statements:



    set value of property list item "moduleName" to "iTunes Artwork"

    set value of property list item "idleTime" to nnn (where nnn is the # of minutes)

    set value of property list item "modulePath" to "/System/Library/Screen Savers/iTunes Artwork.saver"



    Then to make the script run every morning at a certain time, open iCal, choose a calendar or make a new calendar, click today's date and choose New Event, and set the details of the event in iCal as shown in this photo:







    Where the script "SetScreenSaver" or whatever you name it can be anywhere, but most people would keep it in /Users/youracct/Library/Scripts .
  • Reply 4 of 6
    Thanks thats brilliant, just what I've been after.



    Cheers
  • Reply 5 of 6
    averyavery Posts: 1member
    I was trying to do this and was having some problems...so I played around with it and got it to work. Here is what I came up with...



    First find the screensaver file in your "ByHost" folder... it will be ~/library/Preferences/ByHost/com.apple.screensaver.[your host string here]. If you have a few different ones you can sort by date, then set your screensaver the usual way (or change it and set it back)...it will come up to the top. Use Property List Editor.app to look inside. Copy the following into AppleScript Editor and replace the moduleName, path and type items with whatever you see in Property List Editor. Also replace the [your host string here] part.



    Quote:

    set prefsFolder to (path to "pref")'s POSIX path & "ByHost/"

    tell application "System Events"

    \tset prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.apple.screensaver.[your host string here].")'s POSIX path)

    \ttell prefsFile

    \t\tset value of property list item "moduleName" of property list item "moduleDict" to "BOINCSaver"

    \t\tset value of property list item "path" of property list item "moduleDict" to "/Library/Screen Savers/BOINCSaver.saver"

    \t\tset value of property list item "type" of property list item "moduleDict" to 0

    \tend tell

    \tif exists process "System Preferences" then quit application "System Preferences"

    end tell



    I like to switch from BOINC to LCDscrub when I'm doing CPU intensive work. Make sure you take the name of the screensaver from the Property List Editor.app field...in the case of BOINC it says BOINC in the list in the preference, but BOINCsaver in the moduleName field. Hope this helps someone.
  • Reply 6 of 6
    bjornbjorn Posts: 2member
    Hi



    I'm wondering if it's possible to create an applescript that:

    Adds a RSS feed (should go to http://static1.yaycontent.com/pub/RSS/test/pics.rss) as a screensaver

    Switch to the newly created screensaver

    Optionally set some options like display time, screen saver start time and crossfading?



    I want to create an applescript that our customers can download, doble-click, and then get images from our site as their sceensaver. Obviously, if there is a easy way to create an installer instead of an apple script that would be awesome.
Sign In or Register to comment.