I need to use PhotoShop to read scanned color patches (total 288 patches) and record down their CMYK values for other purposes.
I search thru the PS dictionary and forum, have no luck to find any hints. Can someone pls help to provide some clues on how can I achieve it?
I can use PS action to let the eye-dropper to go to the specific image location to pick up the CMYK values one by one, but how can I save the data onto a text file?
This should get you most of what you require. Tweak as you like.
(not convinced I went about the math in the handler CMYK_Values() the right way) but worked in my quick tests.
set Input_Folder to choose folder with prompt "Where the swatches" without invisibles
set CMYK_Log to (path to desktop as Unicode text) & "CMYK_Values.txt"
--
tell application "Finder"
set File_List to files in folder Input_Folder
end tell
--
tell application "Adobe Photoshop CS2"
set User_Notifiers to notifiers enabled
set User_Rulers to ruler units of settings
set User_Dialogs to display dialogs
set notifiers enabled to false
set ruler units of settings to pixel units
set display dialogs to never
end tell
--
repeat with This_File in File_List
tell application "Finder"
set The_File to This_File as alias
end tell
tell application "Adobe Photoshop CS2"
activate
open The_File
set Doc_Ref to the current document
tell Doc_Ref
set Doc_Name to name
-- Get a single pixel selection at location
select region {{10, 10}, {11, 10}, {11, 11}, {10, 11}}
if bits per channel = eight then
if mode = CMYK then
set C to my CMYK_Values(histogram of channel 1)
set M to my CMYK_Values(histogram of channel 2)
set Y to my CMYK_Values(histogram of channel 3)
set K to my CMYK_Values(histogram of channel 4)
set CMYK_Data to Doc_Name & space & ¬
"Cyan = " & C & " Magenta = " & M & ¬
" Yellow = " & Y & " Black = " & K & return
my write_to_file(CMYK_Data, CMYK_Log, true)
else
set Foo to Doc_Name & " Not CMYK file" & return
my write_to_file(Foo, CMYK_Log, true)
end if
else
set Foo to Doc_Name & " Not 8bit file" & return
my write_to_file(Foo, CMYK_Log, true)
end if
-- close without saving
end tell
end tell
end repeat
--
beep 3
activate me
display dialog "All Done." giving up after 6
--
tell application "Adobe Photoshop CS2"
set notifiers enabled to User_Notifiers
set ruler units of settings to User_Rulers
set display dialogs to User_Dialogs
end tell
--
on CMYK_Values(This_Histogram)
repeat with i from 1 to 256
if item i of This_Histogram is 1 then
set The_Value to 100 - ((i - 1) * 0.39215686) as integer
return The_Value
end if
end repeat
end CMYK_Values
--
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file