load image from external file

Hello everyone. I’m new at AppleScript Studio, and I have a roadblock that I cannot seem to get past.

I’m making a simple application that displays an image and presents a text input to type a new name for the file. Hitting ENTER renames the file in the Finder to whatever the new filename is, and it automatically appends the original extension. I have gotten that done without a problem.

Where I am stuck is on how to load an external file from some way other than with a “choose file” command. Here are the three lines of code that I have that choose the file, load the image and then display it:


		set tmpPath to choose file
		set theImage to load image tmpPath
		set image of image view "userImage" of window "mainWindow" to theImage

That works just fine. But I want to know what the first line should be changed to for it to load an image whose path is coded into the script, something like:


		set tmpPath to "HardDrive:Images:picture.jpg"
		set theImage to load image tmpPath
		set image of image view "userImage" of window "mainWindow" to theImage

When I try that, it says that “The variable theImage is not defined.” Why am I getting this error, and what can I do to correct it? Any help is greatly appreciated.

Thanks,
Dave

Man, that only took like a couple of hours for me to figure out. Anyway, here’s the code that finally worked for me:


set tmpPath to "/Volumes/Hard Drive/Images/picture.tif"
set theImage to load image tmpPath
set image of image view "userImage" of window "mainWindow" to theImage

I guess I needed to use the slashes and begin the path with ‘Volumes’ rather than just the hard drive name. Hey, I said I was new at this :slight_smile:

My goal is to eventually make the program select a folder, and grab the names of all image files. Then it will cycle through them, pausing at each one allowing you to rename the file. It’s just for a big photography job I’m doing - I can’t see it being used on a daily basis.

-Dave

The ‘load image’ command takes a slash-delimited posix path, not a colon-delimited one. Just coerce it’s value to a posix path and you should be good to go. This worked for me…

set tmpPath to "Macintosh HD:Users:jed:Images:roadkill.jpg"
set theImage to load image (POSIX path of tmpPath)
set image of image view "userImage" of window "mainWindow" to theImage

j