Switching the focus between two PSD CS2 files / copy path items?

I am opening two equal named EPS files from different folders named “LowRes” and “HighRes” in PSD CS2. The only difference between these two files are, that the files out of folder “LowRes” are at 72 dpi resolution and contain at least one “path item”. The files in “HighRes” are identical besides the resolution of 300 dpi and containing no path items.
Now I want to copy every “path item” from document1 (the LowRes) to document2 (the HighRes).

  1. The script stops telling me, that the second document needs to get the focus to be able inserting a path. “Tell document” doesn’t seem to work. How do I make document2 getting the top fore?
  2. How can I copy all path items from document1 to document2?

This is what I got so far:

tell application “Adobe Photoshop CS2”
set DocumentList to name of every document
set LowResDoc to item 1 of DocumentList
set LowResDoc to document LowResDoc

set HighResDoc to item 2 of DocumentList
set HighResDoc to document HighResDoc

tell LowResDoc --(document1 is active and inserting the path "Test" works fine)
	if exists path items then
		set thepath to name of every path item
		set thepath to item 1 of thepath
		make new path item at LowResDoc with properties {entire path:{}, name:"Test", kind:normal}
	end if
end tell

tell HighResDoc
	activate --(document 2 won't get active, Script stops)
	if not (exists path items) then
		make new path item at HighResDoc with properties {entire path:{}, name:"Test", kind:normal}
	end if
end tell

end tell

Thank you a lot for any input in advance.
Erden

Model: Powerbook 17"
AppleScript: Script Debugger 3.0.9
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

While Jacques System event scripting is ambitious, it is unneccessary, all you need to do it to tell photoshop to set the current document to the document that you want to address. You could also get rid of a few other lines, this works on my computer with two document open:

tell application "Adobe Photoshop CS"
	set DocumentList to every document
	set LowResDoc to item 1 of DocumentList
	set HighResDoc to item 2 of DocumentList
	set current document to LowResDoc
	tell LowResDoc --(document1 is active and inserting the path "Test" works fine)
		if exists path items then
			set thepath to name of every path item
			set thepath to item 1 of thepath
			make new path item at LowResDoc with properties {entire path:{}, name:"Test", kind:normal}
		end if
	end tell
	set current document to HighResDoc
	tell HighResDoc
		if not (exists path items) then
			make new path item at HighResDoc with properties {entire path:{}, name:"Test", kind:normal}
		end if
	end tell
end tell

Hi,
thank you a lot for your input. Works fine with the short version :slight_smile:

May I ask for a further suggestion? How do you create a new path in document2 with the identical properties of path1 in document1? Better: is it possible to copy every path item of document1 to document2?

So far, I put the properties of path1 into a variable, but then I can’t make a new path in document2 with its identical properties. The next thing would be to copy multiple path items from first to second document.


tell LowResDoc
		if exists path items then
			set current to path item 1
			set thepath to name of every path item
			set thepath to item 1 of thepath
			set pathInfo to (get properties of sub path item 1 of path item (thepath))
                     --following line brings up the error "missing argument"
                     make new path item at LowResDoc with properties {pathInfo}
		end if
	end tell
	
	set current document to HighResDoc
	tell HighResDoc
		if not (exists path items) then
			--next line: best would be to say something like: copy/duplicate every path item of LowResDoc to HighResDoc
			--make new path item at HighResDoc with properties {entire path:{}, name:"Test", kind:normal}
                     make new path item at LowResDoc with properties {pathInfo}
		end if
	end tell

Thank you,
Erden

Erden, I have a couple of scripts that deal with transferring data from one file to another in photoshop. The biggest problem that I have encountered so far is with file of the same name script errors not knowing which file is being referenced. Here is a script that will copy and paste all paths from one file to the other it will need some work, for some unknown reason the copy command will copy the path but paste results in nothing yet using system events works fine try it and see if you get the same results? I even tried putting the make clipping path inside a tell block to make it work but with no effect. This errors all the time yet the same command in another script works just as I would expect. I will post this at adobe to see what they think. This script requires that your files have different names for this you could use apples finder script to add prefix to file names then remove it afterwards. Hope this is some sort of help…

set inputFolderA to choose folder -- files with paths
set inputFolderB to choose folder -- files without paths
tell application "Finder"
	set filesListA to files in inputFolderA
	set countA to count of files in folder inputFolderA
	set filesListB to files in inputFolderB
	set countB to count of files in folder inputFolderB
	if (countA) ≠ (countB) then display dialog "You have an uneven amount of pictures!!! check your folders and try again."
end tell
repeat with i from 1 to countA
	tell application "Finder"
		set theFileA to item i of filesListA as alias
		set theFileB to item i of filesListB as alias
	end tell
	tell application "Adobe Photoshop CS"
		activate
		set display dialogs to never
		open theFileA
		set docRefA to the current document
		tell docRefA
			count every path item of docRefA
			if exists (path items whose kind is clipping) then
				set ClipPath to (name of every path item whose kind is clipping)
			end if
		end tell
		repeat with n from 1 to count of path item of docRefA
			select path item n of docRefA
			copy
			deselect path item n of docRefA
			open theFileB
			set docRefB to the current document
			-- the below paste gives no results
			paste
			-- the below paste does give results I don't know why
			tell application "System Events"
				tell process "Adobe Photoshop CS"
					tell menu bar 1
						click menu item "Paste" of menu "Edit"
					end tell
				end tell
			end tell
			deselect path item 1 of docRefB
			set the current document to docRefA
			delay 1
		end repeat
		close docRefA without saving
		set the current document to docRefB
		tell docRefB
			save docRefB
			-- the below is giving errors yet in a script of it own works fine!!!
			set properties of path item ClipPath of docRefB to {kind:clipping}
		end tell
		close docRefB with saving
	end tell
end repeat

Hi Mark,

thank you for your input. It works fine! All I changed is
a) store the filename of the LowResFile and tell Finder to open the equivalent HighResFile with the same name plus a given prefix e.g. “h_”. Before running this script I rename all files with a tool like “R-Name” or “Renamer4Mac”.
Yet, an if_then_else construct is missing to check if the file does really exist…

b) the “paste” command for the copied pathes didn’t work either, so I stuck to your solution with the system events (translated in German). I found a nice tool called “Pre Fab UI Browser”, perhaps worth for others looking at who have to trigger menu element names)

c) to avoid errors while saving the HighResFile with the pathes, I set the properties of every path item to kind:clipping

Here the code so far…


--Selectable folders at start...
--set inputFolderLowRes to choose folder -- files with paths
--set inputFolderHighRes to choose folder -- files without paths

-- Please locate used folders containing the "LowRes"files with paths and "HighRes" files without paths
-- Amount of files in each folder must match!

set inputFolderLowRes to "Volume_A1:Test_%0:LowRes" as alias
set inputFolderHighRes to "Volume_A1:Test_%0:HighRes" as alias

tell application "Finder"
	--get the files to work on
	set filesListLowRes to files in inputFolderLowRes
	set countLowRes to count of files in folder inputFolderLowRes
	set filesListHighRes to files in inputFolderHighRes
	
	set myFilelist to every file of inputFolderHighRes
	copy filesListHighRes to arrDateiListe
	repeat with i from 1 to length of arrDateiListe
		set item i of arrDateiListe to (item i of arrDateiListe as string)
	end repeat
	
	--short check wether amount of files in both folders are identical nor empty
	set countHighRes to count of files in folder inputFolderHighRes
	--if (countLowRes) ≠ (countHighRes) then display dialog "You have an uneven amount of pictures!!! check your folders and try again."
	if countLowRes = 0 then display dialog "Keine Abbildungen im Ordner LowRes gefunden!!! Ordnerinhalte prüfen und erneut versuchen."
	if countHighRes = 0 then display dialog "Keine Abbildungen in Ordner HighRes gefunden!!! Ordnerinhalte prüfen und erneut versuchen."
	if (countLowRes) ≠ (countHighRes) then display dialog "Ungleiche Anzahl an Abbildungen!!! Ordnerinhalte prüfen und erneut versuchen."
end tell

repeat with i from 1 to countLowRes
	tell application "Finder"
		set theFileLowRes to item i of filesListLowRes as alias
		--set theFileHighRes to item i of filesListHighRes as alias
		
		--store the name of the LowResFile with prefix, to search and open its HighRes equivalent later on
		--all HighResFiles must be renamed with a tool according to the chosen prefix before execution 
		set {theFileHighRes} to {"h_" & (name of (info for theFileLowRes))}
		set theFileHighRes to (inputFolderHighRes as string) & theFileHighRes as alias
	end tell
	
	tell application "Adobe Photoshop CS2"
		activate
		set display dialogs to never
		open theFileLowRes
		set docRefLowRes to the current document
		tell docRefLowRes
			count every path item of docRefLowRes
			if exists (path items whose kind is clipping) then
				set ClipPath to (name of every path item whose kind is clipping)
			end if
		end tell
		repeat with n from 1 to count of path item of docRefLowRes
			select path item n of docRefLowRes
			activate
			copy
			deselect path item n of docRefLowRes
			open theFileHighRes
			set docRefHighRes to the current document
			-- the below paste gives no results
			-- paste
			-- the below paste does give results I don't know why
			tell application "System Events"
				tell process "Adobe Photoshop CS2"
					tell menu bar 1
						--click menu item "Paste" of menu "Edit"
						click menu item "Einfügen" of menu "Bearbeiten" --German Menu
					end tell
				end tell
			end tell
			deselect path item 1 of docRefHighRes
			set the current document to docRefLowRes
			delay 1
		end repeat
		close docRefLowRes without saving
		set the current document to docRefHighRes
		tell docRefHighRes
			--save docRefHighRes
			-- the below is giving errors yet in a script of it own works fine!!!
			--set properties of path item ClipPath of docRefHighRes to {kind:clipping}
			
			--seems to work by setting every path item properties
			set properties of every path item of docRefHighRes to {kind:clipping}
		end tell
		close docRefHighRes with saving
	end tell
end repeat

According to the scripting guide for photoshop duplicating of path items is supported yet I can’t get any form of syntax to work just “can’t make clone errors” driving me mad. does anyone have a sample that works. None in the guide just a big blank page thanks adobe.