Image Events - extracting properties of image

Many thanks in advance for any assistance with this issue:
When I run the Script I get the error “Can’t get properties of missing value.”

set this_file to choose file

try
	tell application "Image Events"
		-- start the Image Events application
		launch
		-- open the image file
		set this_image to open this_file
		-- extract the properties record
		set props_rec to properties of this_image
	end tell
	display dialog image_info
on error error_message
	display dialog error_message
end try

It probably means that you’re file isn’t appropriate for Image Events to open. Therefore, it’s can’t provide any properties.

Take a look at the log and you’ll likely see an issue with the ‘open’ line.

Thanks for your comment:

The image file is a simple JPEG and Image Events processes this image in the extended version of this applescript where I manipulate it in other ways.

So what does it say in the log? Oh, I’d suggest removing the try/error lines until you figure out the properities issue as they may obscure what is happening.

GrahamH. Image Events will not work with system aliases on recent versions of macOS. The following worked on my Sonoma computer. Also, see comments regarding variables.

set this_file to (choose file) as text --HFS path

try
	tell application "Image Events"
		-- start the Image Events application
		launch
		-- open the image file
		set this_image to open file this_file
		-- extract the properties record
		set props_rec to properties of this_image
	end tell
	# display dialog image_info --variable doesn't exist
	# display dialog props_rec --variable exists but is a record
on error error_message
	display dialog error_message
end try

Also, it should probably be noted that not all properties of an image can be coerced to text. For example:

set this_file to (choose file) as text --HFS path

tell application "Image Events"
	launch
	set this_image to open file this_file
	name of this_image --> "Willow Creek - 2023.03.02.jpg"
	resolution of this_image --> {72.0, 72.0}
	location of this_image --> folder "Macintosh HD:Users:Robert:Working:"
	location of this_image as text --> Can’t make «class cfol» "Macintosh HD:Users:Robert:Working:" of application "Image Events" into type text.
end tell
1 Like

Many thanks for your comments:

It seem that I was not using the open command correctly, when I should have used:

set this_file to (choose file) as text

tell application "Image Events"
	-- start the Image Events application
	launch
	-- open the image file
	set this_image to open file this_file
	-- extract the properties record
	set props_rec to properties of this_image
	-- purge the open image data
	close this_image
	-- extract the property values from the record
	set the image_info to ""
	set the image_info to the image_info & "Name: " & (name of props_rec) & return
	set the image_info to the image_info & "File: " & (path of image file of props_rec) & return
	set the image_info to the image_info & "Location: " & (path of location of props_rec) & return
	set the image_info to the image_info & "File Type: " & (file type of props_rec) & return
	set the image_info to the image_info & "Bit Depth: " & (bit depth of props_rec) & return
	set the image_info to the image_info & "Res: " & item 1 of (resolution of props_rec) & return
	set the image_info to the image_info & "Color Space: " & (color space of props_rec) & return
	copy dimensions of props_rec to {x, y}
	set the image_info to the image_info & "Dimemsions: " & x & ", " & y
end tell

thanks again for all your advice…

1 Like