CocoaDev

Edit AllPages

A screen saver module is a special NSBundle. Building them is fairly easy once you know what to do. You should be able to get a good idea of what’s involved by reading the ScreenSaver documentation. Otherwise this page describes how to set up a ProjectBuilder project to build a screen saver module.

See also: [Topic]

Here are some sample ScreenSaverView objects, for your coding pleasure. All of these examples require you to plug this code into a screen saver bundle project. See below for help incorporating this source code into a real screen saver module.

Wade Tregaskis’ Silly Balls! screen saver module is simple and well-written. The module is distributed with source code and can be downloaded from VersionTracker: http://www.versiontracker.com/moreinfo.fcgi?id=12503

Son of SillyBalls is an Objective-C port of the original Silly Balls demo. http://developer.apple.com/samplecode/SonOfSillyBalls/index.html

The ScreenSaver section includes some additional information on the screen saver, including pointers to official documentation.


Using Mac OS X 10.1

In Mac OS X 10.1 you can select Standard Apple Plug-Ins -> Screen Saver when creating a new project. This creates source files and links in necessary frameworks for you.


Using Mac OS X 10.0

1) Run Project Builder.app. Currently you need to use Project Builder to create a screen saver module.

2) Create a Cocoa Bundle project. Save it whereever.

3) Add ScreenSaver.framework to your project via the “Add Frameworks…” menu command (cmd-f).

4) Create files for a new Cocoa Objective-C class. Name the files something like FooView.h and FooView.m, where Foo is the name of your screen saver module.

5) Open the header file and make sure your class is a subclass of ScreenSaverView (currently it’s a subclass of NSView). You’ll also want to add a line to import the ScreenSaver headers:

#import <ScreenSaver/ScreenSaver.h>

Flush out your object w/ whatever ivars you like. See SampleScreenSaverViews for some examples of what your header might look like.

6) Open the source file. Override ScreenSaverView classes as necessary to do the animation you want. The documentation for ScreenSaverView does a good job of explaining what-all is here. If you do not edit this file you’ll get a module similar to BasicBlackScreenSaver (it differs in that this file will re-draw itself 30 times a second or so, where Basic Black disables the animation timer.)

See SampleScreenSaverViews for some examples of what your implementation might look like.

7) Click the Targets tab from the left-hand tab-view. Select your target. Click the Build Settings tab that just appeared. Set the install location to:

$(HOME)/Library/Screen Savers

(That’s kind of optional. You only ought to do this if you are going to build your project using “pbxbuild install” in Terminal app. You must run “pbxbuild install” from the top level of your project directory (the directory with your projectname.pbproj directory in it). Many people will find it just as easy to build in Project Builder and then copy the module into their Library/Screen Savers directory in Finder.)

Scroll down and set the WRAPPER_EXTENSION to:

saver

8) Click the Bundle Settings tab. Scroll down to the “Principal Class” field. Enter the name of your object you defined in steps 4-6.

9) Build and install your project.

That’s all there is to it.