Renaming Photoshop Clipping Paths

Hello,

I am starting to learn applescript but haven’t learnt enough to solve this problem. I have a folder of images with paths and clipping paths, some paths are named Path 1, some are not. I want my script to rename all the paths ‘Path 1’, whether or not they are clipping paths. I found this script in an older post:

tell application "Adobe Photoshop CS5.1"
	activate
	set the source_folder to (choose folder with prompt "Choose folder or files for path renaming." without invisibles)
	set the item_list to list folder source_folder without invisibles
	set source_folder to source_folder as string
	
	repeat with i from 1 to number of items in the item_list
		set this_item to item i of the item_list
		set aFile to (source_folder & this_item) as alias
		
		try
			with timeout of 20 seconds
				open aFile showing dialogs never
				tell current document
					set thePathList to every path item
					repeat with thePath in thePathList
						set name of thePath to "Path 1"
					end repeat
				end tell
			end timeout
		end try
		
		save current document
		close current document saving yes
	end repeat
end tell

When I run the script it returns the error “Adobe Photoshop CS5.1 got an error: File/Folder expected” number 1230. The events pane also shows error 10004 and 43, although these don’t stop the process.

I have also tried the script with CS4 and it works fine, but when it finds a file that’s already named ‘Path 1’ it displays a dialog box asking what I’d like to name the image - I don’t want this to happen, I just want Photoshop to skip those files.

So what I’m asking is, can this script be tweaked to work in CS5.1, and can it be altered so that it skips images which are already named correctly.

Thanks heaps for any suggestions.
Wasabi

Hi,

try to specify the file by a file specifier rather than an alias


.
		set aFile to (source_folder & this_item)
.
		open file aFile showing dialogs never

Hi Stefan,

So I add this bit under here?

   set source_folder to source_folder as string

I’ve just realised I can’t test it till I get back to work on Monday, but I’ll test it then!

Thanks for your help.

just replace both lines

set aFile to. and open.

Thanks!

I’ve tried it out this morning - all works great, but do you have any idea how I can prevent it from displaying a dialog box when it opens a file with the clipping path already named 'Path 1"? I’d like it to skip these files.

Thanks again,

If you are looking for a path named “Path 1” use a try/error. This should stop you from your dialog. Your path names should be unique. So if you have multi-paths you will need to account for this. Nothing in your code deals with the path being a clipping path or not?

tell application "Adobe Photoshop CS5"
	set display dialogs to error dialogs
	tell current document
		try
			set myPath to path item "Path 1"
			close saving no
		on error errText number errNum
			set name of first path item to "Path 1"
			close saving yes
		end try
	end tell
end tell

Hi Mark,

Thanks for your help, does this need to be added to the script or replace a portion of it?

Thanks,

I didn’t test but I would construct like so.

set the source_folder to (choose folder with prompt "Choose folder or files for path renaming." without invisibles)
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
--
tell application "Adobe Photoshop CS5"
	set display dialogs to error dialogs
	activate
	repeat with i from 1 to number of items in the item_list
		set this_item to item i of the item_list
		set aFile to (source_folder & this_item) as alias
		with timeout of 20 seconds
			open aFile
			tell current document
				try
					set myPath to path item "Path 1"
					close saving no
				on error errText number errNum
					set name of first path item to "Path 1"
					close saving yes
				end try
			end tell
		end timeout
	end repeat
end tell

Excellent, I have tweaked it a bit, as per earlier suggestions, and it works just the way I want. Thanks heaps for your help. :slight_smile: Here’s the script now.

set the source_folder to (choose folder with prompt "Choose folder or files for path renaming." without invisibles)
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
--
tell application "Adobe Photoshop CS5.1"
	set display dialogs to error dialogs
	activate
	repeat with i from 1 to number of items in the item_list
		set this_item to item i of the item_list
		set aFile to (source_folder & this_item) as string
		with timeout of 20 seconds
			open file aFile showing dialogs never
			tell current document
				try
					set myPath to path item "Path 1"
					close saving no
				on error errText number errNum
					set name of first path item to "Path 1"
					close saving yes
				end try
			end tell
		end timeout
	end repeat
end tell