Confused about variables.

I’m making several changes to an image file, including changing the file name on the disk. Then, I need to open that image again (now with a new name), in Image Events, but I’m getting an error that the variable “this_image” is undefined.

It is probably obvious to you guys, but I’ve tried several combinations, and can’t get it to go.

The other thing that I’ve been unable to get is I want to set a path to a low res folder that is next to the high res folder (same level). The “choose” will always be inside the high res folder. How do I pull back one level?

Here’s the code:

set this_file to choose file
set lowres_folder to folder "Low Res" of folder "Cross Country 2006" of disk "233Gb Movies"
try
	tell application "Image Events"
		launch
		-- open the image file
		set this_image to open this_file
		-- extract the property value
		copy the dimensions of this_image to {xres, yres}
		copy the name of this_file to originalname
		-- purge the open image data
		close this_image
	end tell
	delay 2
	tell application "FileMaker Pro"
		activate
		set field "Original Filename" in current record to originalname as string
		set field "Image Height" in current record to xres as string
		set field "Image Width" in current record to yres as string
		set newname to field "File Name" in current record
	end tell
	tell application "Finder"
		set name of document file this_file to newname
	end tell
	delay 2
	tell application "Image Events"
		launch
		-- THIS IS WHERE THE PROBLEM IS!
		set this_image to open newname
		scale this_image to size 640
		save this_image as JPEG in folder "Low Res" of folder "Cross Country 2006" of disk "233Gb Movies" with icon
		close this_image
	end tell
	
on error error_message
	display dialog error_message
end try

Thanks,
SoCalMacDude

Hello

It seems that you made some errors.

Here I introduced some corrections (I disabled some code for tests purpose).

set this_file to choose file
tell application "Finder" to set lowres_folder to folder "Low Res" of folder "Cross Country 2006" of disk "233Gb Movies" -- EDITED
try
	tell application "Image Events"
		launch
		-- open the image file
		set this_image to open this_file
		-- extract the property value
		copy the dimensions of this_image to {xres, yres}
		copy the name of this_file to originalname
		-- purge the open image data
		close this_image
	end tell
	delay 2
	(*
	tell application "FileMaker Pro"
		activate
		set field "Original Filename" in current record to originalname as string
		set field "Image Height" in current record to xres as string
		set field "Image Width" in current record to yres as string
		set newname to field "File Name" in current record
	end tell
	*)
	set newname to "NouveauNom" -- just for my tests !!
	tell application "Finder"
		set name of document file this_file to newname
	end tell
	delay 2
	
	tell application "Image Events"
		launch
		-- THIS IS WHERE THE PROBLEM IS!
		set this_image to open this_file  --EDITED
		scale this_image to size 640
		--	save this_image as JPEG in folder "Low Res" of folder "Cross Country 2006" of disk "233Gb Movies" with icon
		close this_image
	end tell
	
on error error_message
	display dialog error_message
end try

Yvan KOENIG (from FRANCE mercredi 20 septembre 2006 12:29:16)

Thank you Yvan!!

You solved my problem!!

I don’t fully understand why you can “set this_file to choose file” without any tell, but you need to tell the Finder to set the path variable, but I’m happy that it works!

Thanks for your help.
Ken

Because AppleScript on its own doesn’t ‘know’ about folders as objects and to “Standard Additions.osax” ‘folder’ is a boolean property of an object (the object is a folder or is not). The Finder deals with folders and ‘directories’, i.e. as containers of something. Similarly, the Finder keeps track of where things are.

AppleScript is about communicating with processes to get answers, so you have to ask the process that ‘knows’ what you want. AppleScript understands ‘choose folder’ and ‘choose file’ because it knows to ask the Finder but your path item set lowres_folder to folder “Low Res” of folder “Cross Country 2006” of disk “233Gb Movies” is in the Finder’s terminology.

To get a path to a file in the Script Editor most easily, write "set yourPathNameHere to posix file ", drag the file to the Script Editor, enclose the path that appears (with slashes instead of colons) in quotes and compile it. Lo and behold - a proper AppleScript path to the file appears (set myPath to file “yourHD:Users:etc.”) and the Finder isn’t involved. If you like, you can replace the word ‘file’ with ‘alias’ in the result (not in the original setup) and you have a general purpose path acceptable to any application.

You would have had the same effect using “set myFile to (choose file) as alias” where the ‘as alias’ did the trick for you.