9 Replies Latest reply: Sep 2, 2013 3:08 PM by red_menace
Apple_For_The_Win Level 1 Level 1

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.

Solved by red_menace on Sep 2, 2013 9:45 AM Solved

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).

Reply by red_menace on Sep 2, 2013 7:36 AM Helpful

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.

Reply by red_menace on Sep 2, 2013 3:08 PM Helpful

Not sure why you are having problems, but I created a sample project for comparison - it can be downloaded here.

All replies

  • red_menace Level 6 Level 6
    expertise.desktops
    Desktops

    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.

  • Apple_For_The_Win Level 1 Level 1

    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.

  • red_menace Level 6 Level 6
    expertise.desktops
    Desktops

    There isn't much more to it than that.  Are you getting an error message in the debug console?  Is your outlet property connected to the image well?  What do you have so far?

  • Apple_For_The_Win Level 1 Level 1

    I dragged Screen Shot 2013-09-02 at 11.59.46 AM.png onto the MainMenu.nib page, and pasted the code with the file path into the AppDelegate page, nothing else.

  • red_menace Level 6 Level 6
    expertise.desktops
    Desktops

    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).

  • Apple_For_The_Win Level 1 Level 1

    I did all that, and it's still not working. It's still showing up blank, no error messages. What could I be doing wrong?

  • red_menace Level 6 Level 6
    expertise.desktops
    Desktops

    If the path to your file is not correct the image will be blank, but there will not be an error in the console - are you using the right (POSIX) file path?

  • Apple_For_The_Win Level 1 Level 1

    Yep. I tried several different ones and checked them all multiple times.

  • red_menace Level 6 Level 6
    expertise.desktops
    Desktops

    Not sure why you are having problems, but I created a sample project for comparison - it can be downloaded here.