tell application "Adobe Photoshop CS"
tell document 1
set t to every path item
if t is equal to {} then
display dialog "No paths exist"
else
display dialog "A path exists"
end if
end tell
end tell
This should help you be able to narrow down which files have a path and which don’t.
To check for just clipping paths use something like this:
tell application "Adobe Photoshop CS3"
tell document 1
if exists (every path item whose kind is clipping) then set clippingtest to true
end tell
end tell
To eliminate the need to open PhotoShop you might be able to read the file and search for the mask. It looks like the part of the header that you need is this if there is â„¢’ 8BIMFMsk. The clipping path name is right after the single the TM’. You should be able to use AppleScript text item delimiters to isolate this portion by first searching for the 8BIMFMSK and getting the first text item then the TM’ and getting the last text item. If this is a space then there is not a clipping path. Some testing would need to be done to verify this before I would put it into production use but I believe that it would work. The shell scripting people on the board could probably come up with a better way to get the text and this would make it a lot faster than opening every file in PS to check for the clipping path.
This was done some time ago and I have not looked at it again just recently. It requires Satimage OXSA to be installed. If I recall correctly it works for the 3 file types. It should sort by Clipping path, Saved Path & No Path. Work Paths are hidden or at least to me and therefore NOT considered. It may need some tidying up as it was one of my first attempts at a droplet.
property type_list : {"JPEG", "8BPS", "TIFF"}
property extension_list : {"jpg", "psd", "tif"}
property clip_path_folder : ""
property path_folder : ""
property no_path_folder : ""
--
global clip_paths_in_image
global paths_in_image
--
on open these_items
tell application "Finder"
if not (exists folder "Images with clipping paths" of desktop) then
set clip_path_folder to make new folder at desktop with properties {name:"Images with clipping paths"}
else
set clip_path_folder to folder "Images with clipping paths" of desktop as string
end if
if not (exists folder "Images with paths" of desktop) then
set path_folder to make new folder at desktop with properties {name:"Images with paths"}
else
set path_folder to folder "Images with paths" of desktop as string
end if
if not (exists folder "Images without paths" of desktop) then
set no_path_folder to make new folder at desktop with properties {name:"Images without paths"}
else
set no_path_folder to folder "Images without paths" of desktop as string
end if
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
tell application "Finder"
activate
display dialog "Image sort is done." buttons {"OK"} default button 1 giving up after 6
end tell
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set theList to list folder this_folder without invisibles
repeat (length of theList) times
repeat with j from 1 to (length of theList) - 1
if item j of theList > item (j + 1) of theList then
set {item j of theList, item (j + 1) of theList} to ¬
{item (j + 1) of theList, item j of theList}
end if
end repeat
end repeat
set these_items to theList
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
set clip_paths_in_image to {}
set paths_in_image to {}
try
set find_paths to find text "8BIM“" in this_item with regexp and all occurrences
repeat with i from 1 to (count of find_paths)
set j to matchResult of item i of find_paths
if paths_in_image does not contain j then
set end of paths_in_image to j
end if
end repeat
end try
try
set find_clip_paths to find text "8BIM∑" in this_item with regexp and all occurrences
repeat with i from 1 to (count of find_clip_paths)
set j to matchResult of item i of find_clip_paths
if clip_paths_in_image does not contain j then
set end of clip_paths_in_image to j
end if
end repeat
end try
tell application "Finder"
if clip_paths_in_image is not {} then
move this_item to clip_path_folder
else
if paths_in_image is not {} then
move this_item to path_folder
else
move this_item to no_path_folder
end if
end if
end tell
end process_item
I tried to post this response before and it caused problems with the forum, I’m guessing that there is some sort of null character in the text:
Inspired by Jerome’s comment, I came up with a simple detector; it doesn’t require additional OSAXen, and (probably) will work for any version of PS.
on open (doclist)
repeat with anItem in doclist
if (offset of "" in read (anItem)) > 0 then tell application "Finder" to move anItem to folder "haspath"--assumed is folder exists on desktop
end repeat
end open
The “” should actually contain “8BIM-”, or the first instance of whatever characters that may actually contain, once read. As I said, I can’t post it to the forum.
A quick test with Mark A’s solution with minor modification has this working at least for eps and psd files saved from CS3:
set anItem to choose file
set theData to read (anItem)
if (offset of "8BIM∑" in theData) > 0 then display dialog "Found" --psd files
if (offset of "eoclip" in theData) > 0 then display dialog "Found" --eps files
Marc, there is a null character in the text. It caused me all sorts of headaches when first trying this. I got much better results when using the OSXA over GREP. The files are binary which dumps out all sorts of junk. After the “BIM” (all Photoshop is saved in these markers) there is a “byte” which actually contains a numeric value so Im told. The value in this byte indicates the length of the saved path name string which is terminated by a null character. I would like to be able to use this information but to date this has me stupped. I have had problems myself when trying to post questions about this subject. Saved paths appear in text edit to increase from “BIM” + “null” + “ASCII 208, Unicode U+2013” and increase by + 1 for each in the ASCII table. Clipping path always has the “summation” or what ever thats called. Work paths I have never been able to find?
My script works as a droplet, and marks the files with colour in finder.
on open fileList
tell application "Adobe Photoshop CS3"
activate
-- DO WITH EVERY FILE DROPPED ONTO THE DROPLET
repeat with thisFile in fileList
open thisFile showing dialogs never
tell current document
-- CHECK FOR PATHS
set CountOfPaths to every path item
if CountOfPaths is equal to {} then
-- IF THERE'S NO PATH
tell application "Finder"
-- MAKE RED IN FINDER
set the label index of thisFile to 2
end tell
else
-- IF THERER IS A PATH
tell application "Finder"
-- MAKE GREEN IN FINDER
set the label index of thisFile to 6
end tell
end if
end tell
-- CLOSE THE FILE
close current document saving no
end repeat
end tell
end open