NSUnknownKeyScriptError (7)

The helpful Apple documentation on this is:

An unidentified error occurred; indicates an error in the scripting support of your application.

Thanks XCode team, I kind of got that. :rolleyes: Possible causes would be more helpful. Which is where you smart folks come in. :smiley:

It started happening after I put code to load an image into an image view in my app:

set image of image view “upArrow” of window “adWin” to upArrowPath

Everything exists, the upArrowPath variable is a path to a folder in the users document folder parsed into a POSIX path. The “adWin” window is a secondary window, not visible at launch. When a user clicks a button I set the visibility to true. I then have this code:


                set pathToDocFolder to path to documents folder from user domain
		set pathToImages to (pathToDocFolder as string) & "HotSheetX:images:" as string
		set upArrowPath to POSIX path of (pathToImages as string) & "upArrow.png"
		log upArrowPath
		-->load image
		tell window "adWin"
			set image of image view "upArrow" to upArrowPath
                        -->I've also tried the hardcoded path - "/Users/steve/Documents/HotSheetX/images/upArrow.png" - same error
		end tell

All the paths seem fine when I log them.
Any help would be appreciated

In your code you have “–>load image” but you don’t actually LOAD the image anywhere. You have to load the image before you display it. When you set an objects image, you must supply an actual image object as the argument, not the path to it. Instead of…

tell window "adWin"
	set image of image view "upArrow" to upArrowPath
end tell

… try something like…

set upArrowImage to (load image upArrowPath)
tell window "adWin"
	set image of image view "upArrow" to upArrowImage
end tell

I’m not sure what your app does, but be careful when creating apps that load lots of images. ASStudio does not release image objects after you load them, so if you are repeatedly loading arbitrary images, you could potentially run up quite a tab in memory caused by the retention of all of the images. See the discussion in the docs for the ‘load image’ command on why and how you should release image objects when using ASStudio (using the ‘delete’ command), and check out the image object section in the docs for more about images in general.

j

Hi Jobu,

Many thanks for the excellent information on loading images and related issues. The links to the documentations are excellent and very useful read.

Honestly, I never did think of releasing memory used by a loaded image because I thought that is done automatically. Well…now I have to go back and start releasing those memories before users report “out of memory error” or other such related errors in the few apps that I included repetitive image loading-viewing.

Thanks. As usual, you come up with the useful info that everyone could learn from.

archseed :slight_smile:

Archseed,

While leaving a known memory leak in an app is certainly not ever recommended, if you do so with just a few interface images you’re not going to notice much of a different in memory footprint, since they have to be retained while the app is running anyways. Where this becomes a concern is in apps that allow the user to load an indefinite number of images. If you were creating some sort of image management or manipulation app that loaded lots of images in an image view, you would definitely want to delete the old image every time you loaded a new one. In my opinion, the way in which people typically use applescript studio would lead me to believe that images should be released automatically. I understand why you need to manually release them… to keep things parallel with their obj-c counterparts. But the point behind ASStudio is to make development more accessible to everyone, and burying the concept of releasing images in the documentation for the load image command isn’t exactly giving such an important task the exposure it needs. And, asking entry-level developers to handle more complex topics like freeing memory (which they don’t know about or have to explicitly do when loading the images) almost sounds like asking too much.

j