NS ImageView and Applescript.

Right, im quite a Interface Builder newb and am wondering this…

I have a custom view, I then change its class in IB to NS ImageView.

Then I got stuck, how do I insert an image in NS ImageView.
I am using Applescript to develop the app.

This is the code I got from a friend.

set the contents of image view "Welcome" to "Welcome.tif"

So I created a Applescript with this file. I then in the Applescript in the info bit on IB changed the name of it to Welcome. I have the Welcome.tif file in the resources in Project Builder.

I built it and nothing, the imge does not show up, I tried a variety of ways to connect the Applescript to the nib but none work. How should I connect it?

Thanks
Oliver

Thanks

Take a look to “Daily Dilbert”'s example, at /Developer/Examples/AppleScript Studio/.
Theorically, you must load the image, then use it:

set k to load image "whatever.tiff"
set image of image view x of window y to k

Is there anychance I can speak to you on AIM?

If so my IM is olivercameron@mac.com

It would be quicker than the forums.

you need first to load an image and then set that image to the imageview.

set x to load image “bbbb”
set image of … to “bbb”

and there’s no need to use the extension if your image is stored onto the project

saludos from Argentina!

It still will not work…

My current code is:

set Welcome to load image “Welcome”
set image of image view “Welcome” of window “Main” to Welcome

Now, im a newb really and all I have done is create the Applescript and put it into the Scripts folder. Could someone tell me what to do next :arrow:

To download the current code I have if you want to help, its here:

http://www.olivercameron.co.uk/personal/Maintain Your Mac.sit

Ooooh! I see! :shock:

The first step is connecting your window to the applescript code, so it can be executed properly. So, click the window and go to AppleScript info pane (command + 6) and click both “awake from nib” (within “nib”) and your script (below, “Images.applescript”).

Now, let’s take a look to your main window… Your image view (which is a custom view) IS within a “tab view item”, within a “tab view”… So, if you wish find it, you must assign them a name or call them by index position…
To give’em a name, click both “tab view” and “tab view item” (info pane will show alternativelly “NSTabView Info” and “NSTabViewItem Info” and choose a name for them… I’ll choose “tabviewitem” and “tabview”.

Now, to the code…

on awake from nib theObject
	set Welcome to load image "Welcome"
	set image of image view "Welcome" of tab view item "tabviewitem" of tab view "tabview" of window "Main" to Welcome
	--> or, by index:
	--> set image of image view 1 of tab view item 1 of tab view 1 of window 1 to Welcome
end awake from nib

Anyway, if you wish this image to show without load it programatically, you can drop a image view in your window (cocoa-other tools), and define (in Attributes pane) border=none (this will make it transparent) and icon=Welcome, and the image will show up immediately…

Your app looks nice, good luck! :wink:

THANKYOU SO MUCH!

I really, really appreciate how you’ve helped me! I love this forum!

So, how does one load an image from outside the app? I’m sure its here but I haven’t found it yet.

:twisted:

set theImagePath to "/Path/to/An/ImageDirectory/test.jpg"
set image of image view "imageView" of window "theWindow" to load image theImagePath

Macscripter is not the only place to get info. Apple’s developer resources are in many ways inadequate, but this answer is found easily by searching the apple developer site for “image applescript”. :wink:

j

I found it but then I couldn’t find my original post :slight_smile:

thanks for the info

:twisted: