Start iPhoto screen saver from AppleScript
Starting the screen saver from AppleScript is simple enough:
tell application "System Events" to start current screen saver
Even starting another screen saver than the default from System Preferences is simple, if you want one of the standard screen saver:
tell application "System Events" to tell screen saver "Arabesque" to start
But it becomes much more complicated if you’d like to start the iPhoto screen saver, and use another as the System Preferences default.
Here’s how I did it:
- Go in System Preferences, and select the iPhoto screen saver. Chooses the options you’d like to use.
In Terminal, create a copy of the screen saver preferences file:
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep 'Hardware UUID' | cut -c22-57` file=~/Library/Preferences/ByHost/com.apple.screensaver.$uuid.plist cp $file $file.iPhoto
Go back in System Preferences, and change the screen saver to the other screen saver you’d like to use as your default.
Once you did all that, here’s how to start the iPhoto screen saver from AppleScript:
tell application "System Events" set uuid to do shell script ("/usr/sbin/system_profiler SPHardwareDataType | grep 'Hardware UUID' | cut -c22-57") set theFolder to folder (preferences folder's path & "ByHost") set theFile to "com.apple.screensaver." & uuid & ".plist" do shell script "cd " & POSIX path of theFolder & "; cp " & theFile & " " & theFile & ".orig; cp " & theFile & ".iPhoto " & theFile start current screen saver do shell script "sleep 5; cd " & POSIX path of theFolder & "; cp " & theFile & ".orig " & theFile end tell
- line 2: find the machine’s UUID; this is needed because the screen saver preferences file contains that in it’s name;
- line 3: the folder where the preferences file is: ~/Library/Preferences/ByHost/;
- line 4: the name of the preferences file: com.apple.screensaver.[UUID].plist;
- line 5: create a .orig backup of the current preferences file, and then overwrite it with the iPhoto copy that was created manually above;
- line 6: start the iPhoto screen saver;
- line 7: wait 5 seconds, to allow the iPhoto screen saver some time to launch, then put back the .orig backup we made at line 5, so that your default screen saver will be used when it’s time.
Convoluted? Yes. Achieves the desired result? You bet!
I did this because I wanted to show the iPhoto screen saver when an AppleScript triggered by ScriptSaver was executed. More details in Show/Hide DesktopShelves using a Hot Corner.