I am a beginning scripter. As an exercise I created this script (below) using pieces provided by Apple, which uses Image Events to return various properties of an image file and display it in a dialog box. It works perfectly in Script Editor. When I save it as an application and run it, it works… but the information displayed for Flie Type (previously displayed as RGB for instance) turns into «constant ****RGB». The same kind of transformation happens for the color space and bit depth information. My assumption is that Image Events has these words or phrases tagged as constants. I have tried setting - instead of copying - the information as text, but it makes no difference. Would somebody please take the time to explain to me 1.) Why the output is different when it is run as an app instead of as a script out of Script Editor, 2.) What do I need to do to get it to work as an app, and 3.) If necessary, how to tell the information being assigned to each of these variables that I only want a certain part of it to appear on the dialog. For instance, how can I tell it to delete the “«constant ****” and “»” portions, but display the RGB portion? You can see my futile attempt at this…
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
set this_file to choose file
try
tell application “Image Events”
launch
– open the image file
set this_image to open this_file
-- extract the property value
set xloc to the path of this_file as text
set xsize to the size of this_file
set xdate to the modification date of this_file as text
set xname to the name of this_image as text
copy the resolution of this_image to {xres, yres}
copy the dimensions of this_image to {xdim, ydim}
copy the file type of this_image to xtype
--set xtype to the file type of this_image as text
--if xtype contains "mill" then
--set xtype to "millions of colors" as text
--end if
copy the color space of this_image to xmode
copy the bit depth of this_image to xdepth
-- purge the open image data
close this_image
end tell
--set xsize to file size of this_image
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