Drag & Drop JPEGS in PS to automate Clipping path and pixel flattening

I am creating clipping paths for thousands of images for my client. Anything I can do to move this process a little faster will help.
Every time I open a new JPEG I assign it a clipping path before I begin drawing my path, for which a dialog appears asking me to name it Path 1, followed by another dialog box asking me to assign a pixel flatness. I can’t find any way to automate this in PS, so I am trying to create an AS to drag and drop the jpegs onto. But I still have to deal with the dialog boxes. The script I have works as a drag and drop, and takes me right up to the dialog boxes, which is where I need help.
Is it possible to use an AS to automate responding to these dialog boxes, so I don’t have to take the time to do it manually for each jpeg?

[code]on open fileList
tell application “Adobe Photoshop CS”
open fileList
activate
end tell
saveclippath()
end open

on saveclippath()
set MasterFolder to (path to desktop as string) & “clipping paths” as alias

tell application "Finder"
	set the the_items to every file of MasterFolder
	repeat with i from 1 to number of items in the_items
		set this_item to item i of the_items as alias
		set this_item_name to the name of this_item
		try
			tell application "Adobe Photoshop CS"
				activate
				open this_item showing dialogs never
				do action "Make Clip Path (selection)" from "Default Actions"
				
			end tell
		end try
	end repeat
end tell

end saveclippath[/code]

You can make a new path and then make it the clipping path of the file without dialog boxes:

set myPath to make new path item at beginning with properties {name:"myPath", entire path:{}}
make clipping path myPath flatness 0.5

This makes a blank path and assigns it as the clipping path. Batch a whole folder through and you have a clipping path ready to go when you open the files with the name, clipping, and flatness set.

In looking into it further you don’t need the make clipping path line and you can define the path as well:

make new path item at beginning of document 1 with properties {name:"myPath", kind:clipping, entire path:{{class:sub path info, operation:shape xor, closed:true, entire sub path:{{class:path point info, anchor:{59.0, 31.0}, left direction:{59.0, 31.0}, right direction:{59.0, 31.0}, kind:corner point}, {class:path point info, anchor:{455.0, 31.0}, left direction:{455.0, 31.0}, right direction:{455.0, 31.0}, kind:corner point}, {class:path point info, anchor:{455.0, 324.0}, left direction:{455.0, 324.0}, right direction:{455.0, 324.0}, kind:corner point}, {class:path point info, anchor:{59.0, 324.0}, left direction:{59.0, 324.0}, right direction:{59.0, 324.0}, kind:corner point}}}}}

Depending on what you are doing and the tolerances needed you could conceivably do all if it straight through AppleScript, or javascript for that matter.

I don’t have the time to try myself, but I’m 90% certain a boring old Photoshop action and using Photoshop’s Batch feature will do exactly what you want. Admittedly the Actions don’t always behave as expected, but I’ve found almost anything I can walk through manually with menu selections, dialogs, and button pushes can be turned into Actions.

Barring that, Adobe considers JavaScript their “official” way to automate their apps (over AppleScript) and provide a ScriptListener plugin to capture the necessary JavaScript code. On the complicated Photoshop work I use Listener to get the JavaScript then activate that via AppleScript (I build these solutions in FaceSpan).

Perhaps oddly, I find this easier than having to come here every single time I have a Photoshop automation question (because I don’t find Adobe’s AS Libraries very helpful). Feel like I’m having MacScripters build every Photoshop solution…may as well let Adobe do it. :wink:

Cool. This does exactly what I need to do. On drag & Drop this opens the PS file, assigns a clipping path with no actual path drawn yet, and assigns a pixel flatness. Well done.
[code]on open fileList
tell application “Adobe Photoshop CS”
open fileList
activate
end tell
saveclippath()
end open
on saveclippath()
set MasterFolder to (path to desktop as string) & “clipping paths” as alias
tell application “Finder”
set the the_items to every file of MasterFolder
repeat with i from 1 to number of items in the_items
set this_item to item i of the_items as alias
set this_item_name to the name of this_item
try
tell application “Adobe Photoshop CS”
activate
open this_item showing dialogs never
–get properties of document 1
–set fileheight to {properties:height} of document 1
–set filewidth to {properties:width} of document 1
set myPath to make new path item at beginning of document 1 with properties {name:“Path 1”, kind:clipping, entire path:{{class:sub path info, operation:shape xor, closed:true, entire sub path:{{class:path point info, anchor:{0, 0}, left direction:{0, 0}, right direction:{0, 0}, kind:corner point}, {class:path point info, anchor:{0, 0}, left direction:{0, 0}, right direction:{0, 0}, kind:corner point}, {class:path point info, anchor:{0, 0}, left direction:{0, 0}, right direction:{0, 0}, kind:corner point}, {class:path point info, anchor:{0, 0}, left direction:{0, 0}, right direction:{0, 0}, kind:corner point}}}}}
make clipping path myPath flatness 0.5

			end tell
		end try
	end repeat
end tell

end saveclippath[/code]

Skip,

for the path properties just leave it blank like this:

properties {name:"myPath", entire path:{}}

No need to add in the extra stuff since there is no path. Glad to help, was just laid off so I could use some work like that myself…lol

Calvin, if you are using Adobe Photoshop’s action descriptor code in your scripts then you should take the time to look at X’s tool kit I have found this to be excellent and a massive help to getting all the things that are missing from the app’s applescript dictionary. It will save you both lots of time and headache. That’s if you are not already using it.:wink: If not I will dig out the link for you.:smiley:

Little confused…you mean use Apple’s development environment?

I prefer FaceSpan for my purposes for small, basic app development. For the Photoshop automation, the ScriptListener works really well as long as you have a basic understanding of programming or JavaScript. FaceSpan lets you embed and call the resultant JavaScript so it’s really seamless.

Much easier, for me, to just let Photoshop “watch” and spit-out the code for me rather than spending alot of time figuring out the AppleScript. One of those rare instances I jump outside AppleScript for a solution. Kinda like folks who jump to shell when it’s more expendient. :wink:

I use a variant of this “trick” by letting Excel create VBScript for complex operations (another “watch me” kind of operation), then back-figuring out how to do the same thing in AppleScript. Excel’s dictionaries are horrid, but oddly enough, the AppleScript commands and syntax are 99% identical in VBScript. So once you have the VB, the AppleScript isn’t too hard.

Calvin, Photoshop’s ScriptListener plug-in spits out action descriptor code which is JavaScript based. The tool kit helps by doing lots of conversions and clean up operations on this code. Internally I think that action descriptor code works in a very similar way to apple events. This means its possible to record just about anything thats in the UI and convert it to JavaScript.
Here is the link to the installer (Im using V1.5 at the moment and its excellent) there are a few utilities in this that may prove very useful to yourself or others. I am using this quite a lot now.
http://sourceforge.net/project/showfiles.php?group_id=173281&package_id=207620