Noob: How to select "not CMYK" images from folder?

Hi all,

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”)

set label index of (faulty_image) to 5

end tell

Please help! TIA

Eric

Finder is not going to know what colour space is.

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

Hi,

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 :wink:

2nd Edit: I think, just a additional “!” does it

Mark, Stefan,

thnx guys, appreciate the help.

I used Stefan’s script first and it worked for me, only one small “but”…

It now selects the CMYK images, but what I need is the “Not CMYK” images.
I’m not sure how to change that in the script you sent me.

Eric, I’ve realized and changed it. :slight_smile:

…and what I’ve realized is this: I’m soooo new to this :smiley:

Thanks! Even works in subfolders!

mdfind and mdls are great tools. If I might be permitted to blow my own horn, see: A Tutorial for Using Spotlight in your AppleScripts

You are permitted :wink: Any help is greatly appreciated here. Thnx!

Yes, I’ve got the idea from one of your scripts :smiley:

Stefan,

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.”

Any ideas?

thnx

Eric

Hi Eric,

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

Wow, that was quick. Are you married? :wink:

Gonna give it a go, keep you posted, thnx!!!

Eric

Yep! Smoothly…

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… :slight_smile: )

[edit] never mind, found it, just a checkbox…

OK, here’s The pain again.

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???

Eric

Yes, this is exactly the reason.

Without spotlight it’s much more difficult to parse the data

Stefan,

Well… at least I’ve learned something… Spotlight is of no use here.
So, I’ try to figure out how to access the meta-data on the server.

“Applescript for Dummies” on my desk, Google on my laptop. I’ll get there… eventually.

Tnx for all your help!

The script of Mark at the top of this thread does the same without spotlight.
It uses “Image Events” which is part of the OS