The visualizer included with iTunes just begs to be used as a screensaver. This hack uses a little AppleScript magic and a utility called ScriptSaver to make this possible. Combine this hack with "Extend Your Visualizer Options" [Hack #54] , and your Mac can display any number of visual options when it's inactive.
ScriptSaver (http://homepage.mac.com/swannman/; free), written by Matthew M. Swann, is a screensaver module that, when activated, executes an AppleScript. There are many potential uses of ScriptSaver, limited only by your hacker imagination. When your Mac goes into screensaver mode, you can use ScriptSaver to have it set an away message in iChat, pause iTunes, back up files, or, as in the case of this hack, activate iTunes's visualizer mode.
To install ScriptSaver, expand the .sit file after downloading it and open /System/Library/Screen Savers. Copy the ScriptSaver.saver file into this folder. Open System Preferences and click on the Desktop & Screen Saver icon. Click the Screen Saver tab, and you will see that ScriptSaver is now one of your options for a screensaver.
In and of itself, ScriptSaver doesn't do anything as a screensaver—no flying toasters, no swimming fish. All ScriptSaver does is execute an AppleScript when the screensaver is activated. This means that instead of activating the Flurry screensaver, for example, ScriptSaver makes a call to an AppleScript. Like any other screensaver, you set the parameters that indicate when ScriptSaver should activate via Screen Saver preferences.
For this hack to work, we need to write, save, and point ScriptSaver to an AppleScript. This snippet of code originally appeared at the Mac OS X Hints site (http://www.macosxhints.com/article.php?story=20040205044431199). So, let's get scripting!
For an AppleScript primer, check out "Tame iTunes with AppleScript" [Hack #72] .
property theModule : "Random" tell application "iTunes" if player state is playing then set full screen to true set visuals enabled to true else do shell script "/System/Library/Frameworks/ScreenSaver.framework/ Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -module \"" & theModule & "\"" end if end tell
Before configuring ScriptSaver to run the AppleScript, let's take a look at what the code is doing. First, the code checks whether iTunes is open. If it is, the code tells iTunes to turn on visuals and set the screen mode to Full. If iTunes is not open, the AppleScript instructs Screen Saver to turn on Random mode. If you have a favorite screensaver (for example, Forest), substitute the name of the screensaver in the first line of the AppleScript code. Save the script [Hack #72] .
Go back to System Preferences → Desktop & Screen Saver. Click the ScriptSaver icon in the menu of available screensavers on the left side of the window. Click on the Options button to bring up the ScriptSaver settings, as shown in Figure 4-57.
For this hack, the only field we are concerned with is the Activation Script field. Click the Choose button, navigate to your saved script, and click the OK button. You have now instructed ScriptSaver to run your script whenever the screensaver is activated. If iTunes is playing when the screensaver kicks in, your screen is replaced with the iTunes visualizer. If you've installed any third-party screensavers from "Extend Your Visualizer Options" [Hack #54] , whichever visualizer you have selected in iTunes shows once the screensaver is activated.
Treat this hack as a springboard for your iTunes imagination. Want a particular song to come on, to pause whatever's playing, or to initiate any other scriptable action? Go for it! You'll notice that ScriptSaver also lets you run a script when your machine is awakened from screensaver mode. This means you can have a script that pauses iTunes when the screensaver activates and another script that plays iTunes when the screensaver is deactivated. To pause iTunes, use the following script:
tellapplication "iTunes" pause
Save the AppleScript and tell ScriptSaver to activate it when screensaver mode turns on. Now, here's the script to play iTunes once you wake your Mac from screensaver mode.
tellapplication "iTunes" pause
Make the second script the deactivation script in ScriptSaver, and bingo, when you exit screensaver mode, iTunes will resume playing right where it left off.