Applescript Program Error.

THE APPLICATION
I borrowed some stuff from Cocoa Objects to create a stay-open script that would detect the current iChat status and replace the buddy icon based on that status. Images reside in a pre-determined directory.

THE ERROR
I got my script working from the Script Editor. However, as soon as I save it as a stay-open application, I get this error when launching it:

“Could not run the script ‘iconStatusApp’ because of a program error. -1312”

I’m including my script (which has been stripped of any error trapping) to see if I’m just missing something really obvious.

THE SCRIPT


property pathToiChatIcons : "Macintosh HD:Users:(Change to your user folder name):Pictures:iChatIcons:"
property delayTime : 5

on run
	tell application "iChat"
		my displayIcon()
	end tell
	return delayTime
end run

on idle
	tell application "iChat"
		my displayIcon()
	end tell
	return delayTime
end idle

on displayIcon()
	tell application "iChat"
		if status is equal to available then
			set activeIcon to (pathToiChatIcons & "available.tif")
		else if status is equal to away then
			set activeIcon to (pathToiChatIcons & "away.tif")
		else if status is equal to idle then
			set activeIcon to (pathToiChatIcons & "idle.tif")
		end if
		my iChatIconSetTiffImage(activeIcon)
	end tell
end displayIcon

on iChatIconSetTiffImage(theImageFile)
	tell application "iChat"
		set theImage to open for access file theImageFile without write permission
		set ImageData to read theImage as TIFF picture
		set image to ImageData
		close access theImage
	end tell
end iChatIconSetTiffImage

THE THANKS
Thanks in advance to anyone who can help out with this.

on run 
   tell application "iChat" 
      my displayIcon() 
   end tell 
   return delayTime 
end run

You can re-write this chunk as follow:

my displayIcon()

You don’t need the tell block nor the return statement in the “run” handler.
How are you saving your application? This seems more a save problem that a coding one, since it works when executed from the Script Editor, as you describe…

You can also remove the “tell app…” in the “iChatIconSetTiffImage” handler, since some verbs owned by the Standard Additions could cause confusion to iChat…

I got it to work by taking the file access stuff out of the iChat tell block:

on iChatIconSetTiffImage(theImageFile)
	set theImage to open for access file theImageFile without write permission
	set ImageData to read theImage as TIFF picture
	close access theImage
	
	tell application "iChat" to set image to ImageData

end iChatIconSetTiffImage