Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do I set an ImageWell in Xcode Cocoa-Applescript?

I'm making a little Cocoa-Applescript application in Xcode, and I'm completely new at this. So my questions are:

  • What are the steps, in order, to set an image into the ImageWell, if the image was named "Image.png"?
  • What are the codes to add to the AppDelegate.applescript?


Any help is appretiated, and thanks in advance.

Posted on Sep 2, 2013 6:00 AM

Reply
Question marked as Best reply

Posted on Sep 2, 2013 7:36 AM

The business end of an image well is an NSImageView - the various class references usually have links in the Interface Editor's Quick Help inspector.


The method you are looking for is setImage, but since it uses an NSImage, you will need to create one first by allocating and intitializing it. Assuming that your image well outlet is named myImageWell, you can do something like the following:

set theImage to current application's NSImage's alloc's initWithContentsOfFile_("/path/to/Image.png") myImageWell's setImage_(theImage)


For future reference, you might want to trim your tag list a bit to those relevant to the particular topic. There are also Developer and OS X Technologies communities that have a more relevant audience for these kinds of topics.

9 replies
Question marked as Best reply

Sep 2, 2013 7:36 AM in response to Apple_For_The_Win

The business end of an image well is an NSImageView - the various class references usually have links in the Interface Editor's Quick Help inspector.


The method you are looking for is setImage, but since it uses an NSImage, you will need to create one first by allocating and intitializing it. Assuming that your image well outlet is named myImageWell, you can do something like the following:

set theImage to current application's NSImage's alloc's initWithContentsOfFile_("/path/to/Image.png") myImageWell's setImage_(theImage)


For future reference, you might want to trim your tag list a bit to those relevant to the particular topic. There are also Developer and OS X Technologies communities that have a more relevant audience for these kinds of topics.

Sep 2, 2013 8:46 AM in response to red_menace

I don't understand. I just pasted the code into the Appdelegate file, inbetween the

applicationWillFinishLaunching_(aNotification) handler and replaced the path with the actual one, but the imagewell is still blank. I know I've done something wrong but I don't know what. Could you please give me a more detailed description? I'm an absolute beginner.

Sep 2, 2013 9:45 AM in response to Apple_For_The_Win

OK - when using the Interface Editor, you need to include outlet properties in your script that will represent the instances of the various UI objects. The Interface Editor will look for properties that have a specific signature, so the first thing is to add an outlet property to your script, set to missing value - for example:


property myImageWell : missing value


Once you have added (and saved) your script with the property, it will show up in the Interface Editor. The easiest way to start with would be to select the blue cube that represents your App Delegate, and look in the Connections Inspector to see all of the various connections - you should see the myImageWell property under Outlets. In the Inspector pane, there are connector symbols along the right side - click and drag a connection from the symbol for the myImageWell property to the image well in your user interface. Save the file and you are done - the actual propery values will be set when your application starts up.


That is the general procedure to connect things in your UI to the properties that represent them in your script (there are other goodies such as bindings, but this will get you started). Once connected, you can use the various methods of whatever class your object is an instance of (in this case an image well / NSImageView and its parents).

How do I set an ImageWell in Xcode Cocoa-Applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.