get colors of a vector image in InDesign CS

I can get the color space of a rastor image (jpeg, tiff, etc.) in InDesign CS, but how do I get the colors used in a vector image (illustrator .eps) to know whether it is composed of spot or process colors?

skipdidthis,

I don’t think there is any way to do that directly form Indesign as a vector graphic can contain both spot and process colors at the same time. What would you do with that information if you could get it ?

mm

Read them from the EPS file head. You can get both used process and custom colours. Don’t even need to open them. Im only new to ID so I’ve not gotten so far as to try scripting it but I have something along a similar line that Im playing with at the moment but for Quark appears to work although I need to do some further testing.

Mark, what do you mean by the EPS file head, do you mean in the applescript script or from the InDesign file?
I have created a call-out sheet for routing a mechanical for approval, prior to preflighting and collecting and sending a disk to the printer. How many times have you written the file specs on a piece of tissue overlay of the mechanical, pointing out every font, every image and its name and color makeup, every colored text,etc. Then some idiot along the approval route writes a question on the tissue with a sharpie, or someone else finds a legitimate item that needs changing, and then you have to redo the tissue.
My script creates a new layer over the file, and creates slugs around the outside with arrows that point to the item the slug is referencing. The slug identifies every text frame by font and text color, and every image by name and class. Right now, it can identify the colors used in rastor files, but not in vector files. The user will have to do some editing, getting rid of excess slugs and moving the end point of multiple arrows of the same text color to one slug instead of many, but it sure beats the hell out of doing it by hand, especially when you have to do it more than once. I’ve seen this sort of script for Quark, but not for InDesign, so I’ve made one. There may be such a script out there already, but if not, I would be happy to post this one for the sufferers of other idiots to use. This is InDesign CS, when we get our copies of CS2 or 3, I’ll adapt it.

wow thats sounds really cool… I wish I could be more of a help but Marks idea looks promising :slight_smile:

mm

In my case I have be looking into the idea of searching text patterns within read file. I am rubbish at just about everything text wrangling so I have gone down the route of the Satimage OSXA as Im finding this much easier to do. You can inspect files by just opening them in text edit using Western (Mac OS Roman) and browsing for the info that you require. If its there then you should just be able to define text search patterns. Here is the example that I have at the moment for Illustrator EPS Colors (you will note that swatches that are unused in file both spot & process do not make it to the file head which is nice one less thing to sort. I am still pretty much in the early stages of this so testing has not been too in-depth. In my tests Im just passing all the image paths from quark sorting into type lists then searching. I would presume some thing along a similar line could be implemented with ID. For now try point this at illustrator EPS.

set theFile to alias choose file with prompt "Find me an illustrator EPS file!" without invisibles
--
tell application "Finder"
	set theFile to theFile as alias
end tell
--
set PMS to {}
try
	try
		set myProcess to find text "%%DocumentProcessColors: ([ [:alpha:]]{1,})" in theFile with regexp and string result
	on error
		display dialog "No Process Colours were found." buttons {"Cancel"} default button 1 giving up after 2
	end try
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set myProcess to words 4 thru -1 of myProcess as string
	set AppleScript's text item delimiters to ASTID
	set theDialog to "This EPS uses the PROCESS INK(s)." & return & return & myProcess
	display dialog theDialog buttons {"Cancel"} default button 1 giving up after 6
	--
	try
		set DCC to find text "%%DocumentCustomColors:" in theFile with regexp and all occurrences
		set DCC_OffSet to matchPos of item 1 of DCC
	on error
		display dialog "%%DocumentCustomColors: was not found" buttons {"Cancel"} default button 1 giving up after 2
	end try
	try
		set CMYK_CC to find text "%%CMYKCustomColor:" in theFile with regexp and all occurrences
		set CMYK_OffSet to matchPos of item 1 of CMYK_CC
	on error
		display dialog "%%CMYKCustomColor: was not found" buttons {"Cancel"} default button 1 giving up after 2
	end try
	try
		set myPantones to find text "(PANTONE ([ [:alnum:]]{1,}))" in theFile starting at DCC_OffSet for CMYK_OffSet with regexp and all occurrences
	on error
		display dialog "No PANTONE(s) INK(s) were found." buttons {"Cancel"} default button 1 giving up after 2
	end try
	repeat with i from 1 to (count of myPantones)
		set j to matchResult of item i of myPantones
		if PMS does not contain j then
			set end of PMS to j
		end if
	end repeat
	--
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set PMS to items of PMS as string
	set AppleScript's text item delimiters to ASTID
	set theDialog to "This EPS uses the PANTONE(s) INK(s)." & return & return & PMS
	display dialog theDialog buttons {"Cancel"} default button 1 giving up after 6
end try

Edited due to my poor typing & spelling

I don’t understand your script and I got an error message concerning the word “text” in the line:
set myProcess to find text “%%DocumentProcessColors: ([ [:alpha:]]{1,})” in theFile with regexp and string result

But I adapted your intent into the following script. It crashes in textedit after “end considering” so I think I will close the textedit doc at that point since I no longer need it to deal with the variables. Now I just have to put in some script that hardwires the path to the eps doc to replace the dialog box and see if it runs.

set theFile to alias choose file with prompt "Find me an illustrator EPS file!" without invisibles tell application "Finder" set theFile to theFile as alias end tell tell application "TextEdit" activate tell front document considering case set DocProcess to get first paragraph where it begins with ("%%DocumentProcessColors:" as string) set DocCust to get first paragraph where it begins with ("%%DocumentCustomColors:" as string) end considering set NewProcess to every word of DocProcess as string delete (characters 1 thru 22) of NewProcess set NewCust to every word of DocCust as string delete (characters 1 thru 21) of NewCust set theColors to NewProcess & NewCust end tell end tell

Skipdidthis, you need to get the “Satimage” OSXA and drop it in your library/scripting additions. You should be able to find download link for this at front page of these forums.
then
set myProcess to find text “%%DocumentProcessColors: ([ [:alpha:]]{1,})” in theFile with regexp and string result
– returns “%%DocumentProcessColors:” followed by space then any alpha ranges separated by space greater than 1 in count for example.
“%%DocumentProcessColors: Black”
“%%DocumentProcessColors: Cyan Magenta Yellow Black”
and
set myPantones to find text “(PANTONE ([ [:alnum:]]{1,}))” in theFile starting at DCC_OffSet for CMYK_OffSet with regexp and all occurrences
– returns “Pantone” followed by space then any alpha/numeric ranges separated by space greater than 1 in count for example.
PANTONE 8321 C
PANTONE 7433 C
PANTONE 7414 C
PANTONE 649 C
PANTONE Hexachrome Magenta C
PANTONE Rubine Red C
PANTONE Violet C
PANTONE Orange 021 C
PANTONE 7543 U
PANTONE 8281 U
PANTONE Rhodamine Red U
PANTONE Hexachrome Orange U
PANTONE 107 U
PANTONE Reflex Blue U
PANTONE Warm Red U

Thanks Mark, I’m going to check in to that and see if I can make it work for me.
In the mean time, I got this to work for me, with your tip of getting the information from a textedit file. But TextEdit is so persnickity I will have to do a lot of testing before I feel my solution is 100% reliable.
I found by opening the eps with TextEdit that there are lines beginning with:
“%%DocumentProcessColors” for Process colors
“%%DocumentCustomColors” for the first spot color
“%%+” for each and every other spot color

set ThePath to get file path of theImage as string tell application "TextEdit" activate open file ThePath as alias tell front document considering case try set DocProcess to get (first paragraph where it begins with ("%%DocumentProcessColors:" as string)) on error set DocProcess to {} end try try set Doccustom to get (first paragraph where it begins with ("%%DocumentCustomColors:" as string)) on error set Doccustom to {} end try try set DocPlus to get (every paragraph where it begins with ("%%+ (PANTONE " as string)) on error set DocPlus to {} end try end considering end tell close window 1 make new document at beginning try if exists DocProcess then set the text of front document to DocProcess get the text of front document delete characters 1 thru 25 of front document set finalProcess to the text of front document else set DocProcess to {} end if end try try if exists Doccustom then set the text of front document to Doccustom get the text of front document delete characters 1 thru 24 of front document set finalCustom to the text of front document else set Doccustom to {} end if end try try if exists DocPlus then set paragraph 1 of front document to DocPlus as string get every paragraph of front document delete characters 1 thru 4 of every paragraph of front document set FinalPlus to the text of front document end if end try close window 1 end tell try if exists FinalPlus then set finalCustom to (finalCustom & FinalPlus) else set FinalPlus to {} end if end try try set theSpace to finalProcess & finalCustom on error if exists finalProcess then set theSpace to finalProcess else set theSpace to finalCustom end if end try end try

You can also use GREP to search file headers. I use the technique to scan file headers that have lost their Mac OS resource fork so I can programmatically restore them. I use a hexdump utility to view the raw info in the file, then look for patterns I can search for. You can use a similar technique.

Here’s the hexdump utility:

--
-- Get Hexdump Info v4
-- by Kevin Quosig, 3/28/07
--
-- Used to drag-n-drop files to examine their contents/headers.
--
-- Most code segments courtesy of James Nierodzik of MacScripter
-- http://bbs.applescript.net/profile.php?id=8727
--


--
-- UTILITY HANDLER
--

-- Search and Replace routine using AppleScript Text Item Delimiters "trick"
--
on searchNreplace(parse_me, find_me, replace_with_me)
	
	--save incoming TID state, set new TIDs
	set {ATID, AppleScript's text item delimiters} to {"", find_me}
	
	--using the specified character as a break point to strip the delimiter out and break the string into items
	set being_parsed to text items of parse_me
	
	--switch the TIDs again (replace string)
	set AppleScript's text item delimiters to {replace_with_me}
	
	--coerce it back to a string with new delimiters
	set parse_me to being_parsed as string
	
	--restore incoming TID state
	set AppleScript's text item delimiters to ATID
	
	--return results
	return parse_me
	
end searchNreplace


--
-- MAIN HANDLER
--
on open fileList
	
	-- parse through files dropped onto droplet
	repeat with i from 1 to number of items in fileList
		
		set AppleScript's text item delimiters to {""} --reset delimiters
		set this_item to item i of fileList as string ---pick item to work with
		set this_item_posix to quoted form of POSIX path of this_item --need POSIX path for shell scripts
		set doc_name to name of (info for alias this_item) --used for renaming the TextEdit window
		
		--Improved hexdump script line by TheMouthofSauron at MacScripter
		--http://bbs.applescript.net/viewtopic.php?pid=77811#p77811
		--
		--hexdump with the -C parameter formats the hexdump as columns of hex pairs
		--and then a column with a human-readable "ASCII translation" delimited by a pipe
		--character at the beginning and end of the ASCII column
		--
		--"awk" takes the entire -C formatted hexdump line ($0 = all arguements)
		--and filters-out the hex pairs and the delimiting of pipe characters
		--(return only 16 characters starting at position 62)
		--
		set hex_dump to (do shell script "hexdump -C " & this_item_posix & " | awk '{print(substr($0,62,16))}'")
		
		--remove carriage returns so output is one giant paragraph
		--(allows for TextEdit searching for strings and manual scanning)
		set hex_dump to searchNreplace(hex_dump, return, "")
		
		--write to TextEdit window and rename window to file name to keep things straight
		tell application "TextEdit"
			make new document
			set text of front document to hex_dump
			set name of front window to doc_name
		end tell
	end repeat
end open

Here’s the GREP utility used to take a given input (list of search terms) and output how many times it was found and which list item was found:

--
-- Uses GREP to look into file looking for header string to identify file
--
on grepForString(path_to_grep, search_list)
	my logMe("BEGIN grepForString Handler", 3)
	
	repeat with i from 1 to count of items of search_list
		set current_item to item i of search_list
		my logMe("¢ Match string: " & current_item, 3)
		
		try
			set grep_result to grepMe(path_to_grep, current_item)
			my logMe("¢ Matches found: " & grep_result, 3)
			exit repeat
		on error
			set grep_result to 0
			my logMe("¢ Matches found: " & grep_result, 3)
		end try
	end repeat
	
	my logMe("END grepForString Handler", 3)
	
	return {grep_result, current_item}
	
end grepForString


--
-- Uses GREP to parse a single instance for grepForString
--
-- Sub-handling this gets around AppleScript problem when GREP returns zero
--
on grepMe(file_path, search_item)
	set file_path_POSIX to POSIX path of file_path
	set shell_string to ("grep -ch \"" & search_item & "\" " & quoted form of file_path_POSIX)
	return (do shell script shell_string)
end grepMe

So for example, if grepForString is fed this list…

property g_headers_pdf_version : {"%PDF-1.3.%", "%PDF-1.4.%", "%PDF-1.5.%", "%PDF-1.6.%"} --PDF versions 4, 5, 6, and 7 in that order

…and the return is greater than zero, then I’ve got a PDF. To be sure, I can also check against…

property g_headers_illustrator_eps : {"PS-Adobe-2.0 EPSF-", "PS-Adobe-3.0 EPSF-", "PS-Adobe-3.1 EPSF-"} --valid Illustrator EPS files have this additional header info

…on the off chance it’s an Illustrator file, not a PDF.

You can use similar techniques to look for other strings for other reasons (for example, given the header strings that look for colors embedded in EPS files).

Hope this helps!

Calvin, very nice I followed this topic while you were putting this together. My skills in the use of shell are pretty limited hence the decision for now to go for the OSXA for the time being. I believe we are doing almost the same sort of thing but in different manner. When I get the chance I will re-address this subject, hopfully picked up enough to switch to a shell/vanilla applescript version. Question from what I see in the example shown you are in fact not looking for patterns but exact matches from predefind lists. I know your reason behind this so we don’t really need to go into that but If you were looking for patterns say colours by a set naming convention then you would not need to make huge list but use regular expressions in the search. I’ve managed to do some of this for PDF & EPS versions as well as PDF box measures etc. Is this how you are approaching this but using shell? here is an example that contains the boxes searches for my Quark created PDF’s which will find things like:
“MediaBox[0 0 651.968 898.583]”
“BleedBox[19.358 19.551 631.642 878.449]”

set Q1 to "Do you want to include all the subfolders" & return & "within your folder selection?"
set theDialog to display dialog Q1 buttons {"No", "Yes", "Cancel"} default button 1 with icon note
if button returned of theDialog is "Yes" then
	set inputFolder to choose folder with prompt "Where is the top level folder of PFD's?" without invisibles
	tell application "Finder"
		set filesList to (files of entire contents of inputFolder whose name extension is "pdf" or file type is "PDF ")
	end tell
else
	tell application "Finder"
		set inputFolder to choose folder with prompt "Where is the folder of PFD's?" without invisibles
		set filesList to (files of inputFolder whose name extension is "pdf" or file type is "PDF ")
	end tell
end if
set countA to count of filesList
if countA = 0 then
	tell application "Finder"
		display dialog "Your selection contained no PDF files to check!" buttons {"Cancel"} default button 1 giving up after 3
	end tell
end if
--
repeat with aFile in filesList
	tell application "Finder"
		set theFile to aFile as alias
		set docName to name of theFile
	end tell
	try
		set PDFlevel to find text "PDF-1[.][3-7]" in theFile with regexp and string result
		set theLevel to the result
	on error
		set theLevel to "Not Found"
	end try
	set DN to true
	try
		set Device_N to find text "DeviceN" in theFile with regexp and string result
		set SepsType to the result
	on error
		set DN to false
	end try
	if DN is false then
		try
			set Device_CMYK to find text "Separation/All/DeviceCMYK" in theFile with regexp and string result
			set SepsType to "DeviceCMYK"
		on error
			set SepsType to "Grayscale"
		end try
	end if
	set MediaBox to my GREPSearch(theFile, "MediaBox")
	set BleedBox to my GREPSearch(theFile, "BleedBox")
	set TrimBox to my GREPSearch(theFile, "TrimBox")
	set CropBox to my GREPSearch(theFile, "CropBox")
	--
	my writelog(docName, theLevel, SepsType, MediaBox, BleedBox, TrimBox, CropBox)
end repeat
--
set ReadFile to ((path to desktop folder) as text) & "PDF Info Log.txt" as alias
tell application "TextEdit"
	activate
	open ReadFile
end tell
--
on GREPSearch(theFile, BoxType)
	set SearchString to BoxType & "\\[[. [:digit:]]{1,}\\]"
	try
		set BoxText to find text SearchString in theFile with regexp and string result
		set FoundString to the result
		set BoxText to my BoxMeasure(BoxType, FoundString)
		return BoxText
	on error
		return ("No " & BoxType) as text
	end try
end GREPSearch
--
on BoxMeasure(BoxType, FoundString)
	set x to text ((BoxType's length) + 2) thru -2 of FoundString
	set {L, B, R, T} to my GetTextItem(x, " ", 0)
	set {L, B, R, T} to {L as number, B as number, R as number, T as number}
	set H to (((((T - B) / 72) as inches) as centimeters) as number) * 10
	set W to (((((R - L) / 72) as inches) as centimeters) as number) * 10
	set thisHeight to my RoundDecimal(H, 3, to nearest)
	set thisWidth to my RoundDecimal(W, 3, to nearest)
	return thisWidth & "mm " & thisHeight & "mm" as string
end BoxMeasure
--
on RoundDecimal(NumberToRound, DecimalPlace, RoundType)
	set RoundFactor to 10 ^ DecimalPlace
	NumberToRound * RoundFactor
	round result rounding RoundType
	result / RoundFactor
end RoundDecimal
--
on GetTextItem(ThisString, ThisDelim, ThisItem)
	copy the text item delimiters to OldDelims
	set the text item delimiters to ThisDelim
	if class of ThisItem is list then
		set fromItem to (item 1 of ThisItem) as integer
		set toitem to (item 2 of ThisItem) as integer
		set arrItem to (text items fromItem thru toitem of ThisString)
	else
		set arrItem to every text item of ThisString
	end if
	set the text item delimiters to OldDelims
	if class of ThisItem is list then
		return arrItem as text
	else
		if ThisItem is not 0 then
			return (item ThisItem of arrItem) as text
		else
			return arrItem
		end if
	end if
end GetTextItem
--
on writelog(docName, theLevel, SepsType, MediaBox, BleedBox, TrimBox, CropBox)
	set theLog to ((path to desktop folder) as text) & "PDF Info Log.txt"
	try
		open for access file the theLog with write permission
		write (docName & tab & theLevel & tab & SepsType & tab & MediaBox & tab & BleedBox & tab & TrimBox & tab & CropBox & return) to file the theLog starting at eof
		close access file the theLog
	on error
		try
			close access file the theLog
		end try
	end try
end writelog