I’ve been trying to select all images in a folder that are not CMYK images.
All I get is error “unknown object”
What did I do wrong?
set checkfolder to choose folder with prompt “Select folder to check.”
tell application “Finder”
set faulty_image to files of folder checkfolder whose (“color space” is not “CMYK”)
Also in ( I assume you are using) Tiger the set label can not be used on a group of files.
It has to iterate through all the files (one at a time) your would need to use a repeat loop. (Can be Slow)
You can use the ‘image events’ app which comes with the Mac.
Check this link out on the Apple site which will give you some examples of scripts to do what you want.
Here also is one i have quickly adapted from the site to show you.
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}
tell application "Finder"
activate
try
set the source_folder to choose folder with prompt "Pick a folder containing the images to process:"
set these_files to every file of the source_folder whose file type is in the type_list or name extension is in the extension_list
repeat with i from 1 to the count of these_files
set this_path to (item i of these_files) as string
tell application "Image Events"
set this_image to open file this_path
-- IMAGE PROCESSING STATEMENTS GO HERE
set theC to color space of this_image as string
close this_image
end tell
-- FINDER ACTIONS SUCH AS MOVE, DUPLICATE, OR DELETE GO HERE
set CMYK to "CMYK"
if theC is not CMYK then
set label index of alias this_path to 1
end if
end repeat
on error error_message
display dialog error_message buttons {"OK"} default button 1
end try
end tell
This is just one way of doing it, there maybe better ways but it should give you an idea
as Mark mentioned, there is no color space property in the Finder.
Here a solution using spotlight metadata to find the pictures
set inputFolder to quoted form of POSIX path of (choose folder with prompt "Select folder to check.")
set FoundPic to paragraphs of (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemColorSpace != \"CMYK\"'")
repeat with i in FoundPic
set thisPic to POSIX file i
tell application "Finder" to set label index of thisPic to 5
end repeat
Edit: sorry, this finds all CMYK pics, not all pics which are not CMYK
I’ll try to fix that
you can shoot me up a tree… yesterday your script worked just fine.
Today I wanted to show some colleagues the All New Magic Script and guess what? No go…
set inputFolder to quoted form of POSIX path of (choose folder with prompt “Kies de map die je wilt controleren.”)
set FoundPic to paragraphs of (do shell script “mdfind -onlyin " & inputFolder & " ‘kMDItemColorSpace != "CMYK"’”)
repeat with i in FoundPic
set thisPic to POSIX file i
tell application “Finder” to set label index of thisPic to 1
end repeat
“POSIX file i” gets highlighted with an error report (in dutch since my system is dutch)
It says something like “POSIX file “” can not be converted to type reference.”
This error occurs, if no file matches the search criteria.
This traps the error
set inputFolder to quoted form of POSIX path of (choose folder with prompt "Kies de map die je wilt controleren.")
set FoundPic to paragraphs of (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemColorSpace != \"CMYK\"'")
if item 1 of FoundPic is "" then
display dialog "No matches found" buttons {"OK"} default button 1
return
end if
repeat with i in FoundPic
set thisPic to POSIX file i
tell application "Finder" to set label index of thisPic to 1
end repeat
One more question though… when I save the script as an app, on double click the app asks me to select either Run or Quit.
(I know, I’m a pain… but I’m learning… )
On a local disk it all works fine, but on a server (XServe) it doesn’t.
Spotlight is used in this script. Could the problem be that the server isn’t indexed by Spotlight?
Whaaaahhhhhh!!! Will I ever learn how to do this???