Adding Counting Integers to Photoshop PNG Files

I’m new to Applescript and I’m trying to write a script for Photoshop that will move the base layer of a layer mask to create high resolution PNG files of the mask with different fills. There is actually two questions I have:

  1. The PNG files I’m getting are 72 dpi but I want them to be 300 dpi

  2. I haven’t created a loop yet but when I run the script twice the new file just overwrites the old file. When I add the loop, I would like the script to identify the file name and either add an integer prefix like 0000_XXX_XXX.png or XXX_XXX_0000.png so I can easily save then unique fills with a variable amount of integers in the file name to the destination. I’ve tried a few scripts that I found on this site and others without success, it just keeps overwriting the original file.

here is what I have:

tell application “Adobe Photoshop 2020”
tell current document
set selectedLayer to “Layer 1”
translate layer 1 delta x -0.11
end tell
end tell
process_item(“Macintosh HD:Users:llabon:desktop:Woodland_Camo_Outputs:Faded_Camo_Clipping_Mask.png”)
on process_item(this_item)
set thePath to this_item as string
tell application “Adobe Photoshop 2020”
set theDocument to current document
export theDocument in thePath as save for web with options {class:save for web export options, web format:PNG, quality:300}
end tell
end process_item

Any help would be appreciated!

Thank you in advance,
Louie

I have not “Adobe Photoshop 2020” to test the following script. So, try yourself:


property aDesktop: (path to desktop folder) as string
property templateName: aDesktop & "Woodland_Camo_Outputs:Faded_Camo_Clipping_Mask"
property aNameNumber: 0

tell application "Adobe Photoshop 2020" to tell current document
set selectedLayer to "Layer 1"
translate layer 1 delta x -0.11
end tell

tell application "Finder"
   repeat
       set aNameNumber to aNameNumber + 1
       set aNumString to formatNumber(aNumber) of me 
       set filePath to templateName & "_" & aNumString & ".png"
       if Not (exists file filePath) then exit repeat
   end repeat
end

process_item(filePath) of me

--------------------------------------------------------------------------------------

on process_item(aPath)
tell application "Adobe Photoshop 2020"
set theDocument to current document
export theDocument in aPath as save for web with options {class:save for web export options, web format:PNG, quality:300}
end tell
end process_item

on formatNumber(aNumber)
	set aNum to aNumber as string
	if aNumber < 1000 then set aNum to "0" & aNum
	if aNumber < 100 then set aNum to "0" & aNum
	if aNumber < 10 then set aNum to "0" & aNum
end formatNumber

Thank you for the reply KniazidisR, I will give that a try.

Hi. There are fundamental misunderstandings. The “quality” property isn’t equivalent to PPI; that value is a compression indicator that only goes up to 100 and has no applicability to PNG files. Images exported under the ‘save for web’ scheme will always be 72dpi, because that’s the function’s expected behavior. You can export at that effective size (with quality degradation).

tell application "Finder" to set theFiles to (choose folder)'s files as alias list --files for processing (in a folder that's not the save location) 
set saveLocus to (path to desktop as text)

tell application "Adobe Photoshop CS3" to repeat with Counter from 1 to count theFiles
	open (theFiles's item Counter)
	tell document 1
		resize image resolution 300 resample method bicubic
		export it in file ((saveLocus) & ((get name) & Counter)) as save for web with options {web format:PNG} with replacing
		close without saving
	end tell
end repeat