This script is intended to be a droplet which returns selected properties of an image file to a dialog box, using Image Events.
Before turning it into a droplet it worked fine as an openable application.
I am getting NSCannotCreateScriptCommandError[b] and I can’t figure it out. I have spent HOURS trying to research this. Any help would be appreciated!
property type_list : {“PDF”, “TIFF”, “JPEG”, “GIF”, “BMP”, “Quicktime Image”, “PICT”, “Photoshop”, “EPS”}
property extension_list : {“jpg”, “jpeg”, “tif”, “tiff”, “eps”, “bmp”, “gif”, “pict”, “psd”}
– This droplet processes files dropped onto the applet
on open these_items
repeat with i from 1 to the count of these_items
set this_image to item i of these_items
set the item_info to info for this_image
if (folder of the item_info is false) and ¬
(alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
try
tell application "Image Events"
launch
-- open the image file
open this_image
-- extract the property value
set xloc to the path of this_image as text
set xsize to the size of this_image
set xdate to the modification date of this_image as text
set xname to the name of this_image as text
set {xres, yres} to resolution of this_image
set {xdim, ydim} to the dimensions of this_image
set xtype to the file type of this_image
----
if (xtype is TIFF) then
set xtype to "TIFF"
else if (xtype is PDF) then
set xtype to "PDF"
else if (xtype is text) then
set xtype to "Text"
else if (xtype is EPS) then
set xtype to "EPS"
else if (xtype is MacPaint) then
set xtype to "MacPaint"
else if (xtype is JPEG) then
set xtype to "JPEG"
else if (xtype is GIF) then
set xtype to "GIF"
else if (xtype is QuickTime Image) then
set xtype to "QuickTime Image"
else if (xtype is BMP) then
set xtype to "BMP"
else if (xtype is Photoshop) then
set xtype to "Photoshop"
else if (xtype is PICT) then
set xtype to "PICT"
else
set xtype to "Unrecognized file type" as text
end if
------
set xmode to the color space of this_image
----
if (xmode is RGB) then
set xmode to "RGB"
else if (xmode is Lab) then
set xmode to "Lab"
else if (xmode is CMYK) then
set xmode to "CMYK"
else if (xmode is Gray) then
set xmode to "Gray"
else
set xmode to "Unrecognized color mode" as text
end if
------
set xdepth to the bit depth of this_image
----
if (xdepth is black & white) then
set xdepth to "Black & white"
else if (xdepth is thousands of colors) then
set xdepth to "Thousands of colors"
else if (xdepth is grayscale) then
set xdepth to "Grayscale"
else if (xdepth is two hundred fifty six grays) then
set xdepth to "256 grays"
else if (xdepth is sixteen grays) then
set xdepth to "16 grays"
else if (xdepth is millions of colors) then
set xdepth to "Millions of colors"
else if (xdepth is two hundred fifty six colors) then
set xdepth to "256 colors"
else if (xdepth is millions of colors plus) then
set xdepth to "Millions of colors plus"
else
set xdepth to "Unrecognized color depth" as text
end if
------
-- purge the open image data
close this_image
end tell
display dialog ("Image name: " & xname & return) & return & ("Location path: " & xloc & return) & return & ("Modification date: " & xdate & return) & return & "File size: " & round_truncate(number_to_text(xsize / 1024), 3) & " KB" & return & return & ("Resolution: " & xres & " x " & yres & " dpi" & return) & return & ("Dimensions: " & xdim & " x " & ydim & " pixels" & return) & return & ("File type: " & xtype & return) & return & ("Color mode: " & xmode & return) & return & ("Bit depth: " & xdepth) buttons {"Thanks!"} default button 1
on error error_message
display dialog "Doh!" & return & error_message with icon stop
end try
else
display dialog "This is not a recognized file type. This application recognizes standard image file types only." with icon stop
end if
end repeat
end open
on number_to_text(this_number)
set this_number to this_number as text
if this_number contains “E+” then
set x to the offset of “.” in this_number
set y to the offset of “+” in this_number
set z to the offset of “E” in this_number
set the decimal_adjust to characters (y - (length of this_number)) thru ¬
-1 of this_number as string as number
if x is not 0 then
set the first_part to characters 1 thru (x - 1) of this_number as string
else
set the first_part to “”
end if
set the second_part to characters (x + 1) thru (z - 1) of this_number as string
set the converted_number to the first_part
repeat with i from 1 to the decimal_adjust
try
set the converted_number to ¬
the converted_number & character i of the second_part
on error
set the converted_number to the converted_number & “0”
end try
end repeat
return the converted_number
else
return this_number
end if
end number_to_text
on round_truncate(this_number, decimal_places)
if decimal_places is 0 then
set this_number to this_number + 0.5
return number_to_text(xsize div 1)
end if
set the rounding_value to "5"
repeat decimal_places times
set the rounding_value to "0" & the rounding_value
end repeat
set the rounding_value to ("." & the rounding_value) as number
set this_number to this_number + rounding_value
set the mod_value to "1"
repeat decimal_places - 1 times
set the mod_value to "0" & the mod_value
end repeat
set the mod_value to ("." & the mod_value) as number
set second_part to (this_number mod 1) div the mod_value
if the length of (the second_part as text) is less than the ¬
decimal_places then
repeat decimal_places - ¬
(the length of (the second_part as text)) times
set second_part to ("0" & second_part) as string
end repeat
end if
set first_part to this_number div 1
set first_part to number_to_text(first_part)
set this_number to (first_part & "." & second_part)
return this_number
end round_truncate
[/b]