Trying to write a script, which should browse thru the folder containing images and write the file name, resolution color space to a text file. I am using Script Debugger on Mac 10.5.7.
When i run it as Compiled Script from debugger, script writes the file info properly.
Eg: Ducky.tif 72 RGB
But, after i saved the script into an application and ran the application, i see additional info, which is not required.
Eg: Ducky.tif 72 «constant ****RGB»
Please advise.
set myFolder to choose folder with prompt "Choose your folder:"
tell application "Finder"
set imageList to myFolder's document files
set theFilePath to (path to desktop as string) & "FileList.txt" as string
set theFileReference to open for access theFilePath with write permission
set eof theFileReference to 0
repeat with i from 1 to (count of imageList)
set theImage to item i of imageList
tell application "Image Events"
launch
set imRef to open theImage as alias
tell imRef
set {x, y} to resolution
set colSpace to color space
set imageName to name
close imRef
tell application "Finder" to write imageName & tab & (x as integer) & tab & colSpace & return to theFileReference as text
end tell
end tell
end repeat
close access theFileReference
end tell
color space is a constant, not a string, and the Finder doesn’t know this constant. Coercing it to text avoids the problem.
By the way. read/write is a scripting addition and doesn’t need a target application.
And in your script are too many nested tell blocks, which can also cause problems
set myFolder to choose folder with prompt "Choose your folder:"
tell application "Finder" to set imageList to myFolder's document files
set theFilePath to (path to desktop as string) & "FileList.txt" as string
set theFileReference to open for access theFilePath with write permission
set eof theFileReference to 0
launch application "Image Events"
repeat with i from 1 to (count of imageList)
set theImage to item i of imageList as alias
tell application "Image Events"
set imRef to open theImage
tell imRef
set {x, y} to resolution
set colSpace to color space as text
set imageName to name
close imRef
end tell
end tell
write imageName & tab & (x as integer) & tab & colSpace & return to theFileReference
end repeat
close access theFileReference
Hi StefanK,
Thanks a million for the modified script and explanation.
I have modified the script to cater for EPS files from Photoshop and Illustrator.
Now i am facing another issue (Intermittent problem). Once in a while when i run the script, getting error message “The Variable imRef is not defined”.
i am struggling to fix this. Would appreciate, if you could look at the script and advise the better way to address this issue.
set myFolder to choose folder with prompt "Choose your folder:"
tell application "Finder"
set imageList to myFolder's document files
set theFilePath to (path to desktop as string) & "FileList.txt" as string
set theFileReference to open for access theFilePath with write permission
set eof theFileReference to 0
write "Image Name" & tab & "Resolution" & tab & "Dimension (Inches)" & tab & "Color Mode" & return to theFileReference
repeat with i from 1 to (count of imageList)
set theImage to item i of imageList
tell application "Image Events"
open theImage as alias
if creator type of theImage = "8BIM" and file type of theImage = "EPSF" then
tell application "Finder" to set The_File to theImage as alias
set props_rec to properties of theImage
set imageName to name of theImage
my EPS_Res(The_File)
tell application "Finder" to write imageName & tab & result & return to theFileReference -- i have to use target app. here, if not getting error message
else if creator type of theImage is "ART5" or kind of theImage is "Encapsulated Postscript" then
set props_rec to properties of theImage
set imageName to name of theImage
tell application "Finder" to write imageName & tab & "Illustrator File" & return to theFileReference
else
tell application "Finder" to set The_File to theImage
my Tiff_Res(The_File)
tell application "Finder" to write (result as text) & return to theFileReference
end if
end tell
end repeat
close access theFileReference
end tell
on EPS_Res(The_File)
try
set HiResBox to find text "%%HiResBoundingBox: [. [:digit:]]{1,}" in The_File with regexp
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set Height_Points to text item -1 of matchResult of HiResBox
set Width_Points to text item -2 of matchResult of HiResBox
set AppleScript's text item delimiters to ASTID
on error
set HiResBox to ""
end try
try
set ImageData to find text "%ImageData: [ [:digit:]]{1,} \"beginimage\"" in The_File with regexp
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set Height_Pixels to text item 3 of matchResult of ImageData
set Width_Pixels to text item 2 of matchResult of ImageData
set col_space to text item 5 of matchResult of ImageData
set AppleScript's text item delimiters to ASTID
on error
set ImageData to ""
end try
if HiResBox ≠"" and ImageData ≠"" then
set Height_Res to (Height_Pixels / (Height_Points / 72)) as integer
set Width_Res to (Width_Pixels / (Width_Points / 72)) as integer
set heightImage to (Height_Pixels / Height_Res)
set heightImage to (round (heightImage * 100)) / 100
set widthImage to (Width_Pixels / Width_Res)
set widthImage to (round (widthImage * 100)) / 100
if col_space = "1" then
set col_space to "Bitmap/Grayscale"
else if col_space = "2" then
set col_space to "LAB"
else if col_space = "3" then
set col_space to "RGB"
else if col_space = "4" then
set col_space to "CMYK"
else if col_space = "5" then
set col_space to "MultiChannel"
end if
return Height_Res & tab & widthImage & " x " & heightImage & tab & col_space
else
return false
end if
end EPS_Res
on Tiff_Res(The_File)
tell application "Image Events"
set imRef to open The_File as alias
tell imRef
set {x, y} to resolution
set colSpace to color space as text
set imageName to name
set {m, n} to dimensions
set widthImage to (m / x)
set widthImage to (round (widthImage * 1000)) / 1000
set heightImage to (n / y)
set heightImage to (round (heightImage * 1000)) / 1000
close imRef
return (imageName & tab & (x as integer) & tab & (widthImage & " x " & heightImage) & tab & (colSpace as text))
end tell
end tell
end Tiff_Res