LNS Home
FaceSpan 4.3
FaceSpan 4 Home
x Download
x Documentation & Examples
 
bullet Progress Dialog
bullet Dock Icon
bullet Browser View
bullet DTI Tutorials
x O'Reilly MacDevCenter.com
 
bullet Building Applications with AppleScript and FaceSpan
Join the FaceSpan Mailing List
x AppleScript/Scripting Links
Products
Affrus 1.0
x FaceSpan 4.3
Script Debugger 4.0
Site Contents
Home Page
bullet Mark’s Blog
Product Registration
Bug Reporting
x Freeware
Contacting Us

Dock Icon Example

Download Example Project(140K)

This example shows how to alter Dock icon of a FaceSpan application while it's running. You can use your application's Dock icon to indicate the state of your application, the progress of long-running operations, or to indicate errors.

Preparing Icons

Application and Dock icons are expected to be 128x128 pixels in size. You can use any image format (JPEG, GIF, PNG, TIFF, icns) for your image. Since the Dock floats over other content on your screen, Dock icons should have a transparent background. For this example, we are using the following icons:

Icons

Once you've created your icons, add them to the Images section of your FaceSpan project:

project

Controlling the Dock Icon

The FaceSpan application object provides access to the application's Dock icon through the icon image property. Setting this property instantly alters the icon displayed for your application in the Dock.

For this example, we have a window with a series of radio buttons to select the Dock icon to present. We also have an image view in the window to show a preview of the current Dock icon.

windw

We then attach the following code to the matrix of radio buttons:

property pAppIcon : missing value
property pSmileImage : missing value
property pCoolImage : missing value

on awake from nib theObject
   -- cache the images we'll be using
   set pAppIcon to load image "NSApplicationIcon"
   set pSmileImage to load image "smile"
   set pCoolImage to load image "cool"
end awake from nib

on clicked theObject
   local theName

   -- For radio buttons, theObject is the cell that was clicked
   -- In our case, we have named the cells 'none', 'smile' and 'cool'

   set theName to name of theObject
   if theName is "smile" then
      set image of image view "preview" of window "main" to pSmileImage
      set icon image to pSmileImage
   else if theName is "cool" then
      set image of image view "preview" of window "main" to pCoolImage
      set icon image to pCoolImage
   else
      -- otherwise, reset the dock icon to the application's icon
      set image of image view "preview" of window "main" to my pAppIcon
      set icon image to my pAppIcon
   end if
end clicked

The awake from nib handler caches references to the images we'll be using for the Dock icon. The clicked handler responds to changes in the radio buttons. This code does two things:

  • displays the new Dock image in the window's preview image view
  • changes the application's Dock image

This QuickTime movie shows how the Dock responds when this application runs:


Copyright © 1998-2007 Late Night Software Ltd. - All Rights Reserved.