Help with Photoshop script

I’m trying to write a script in which any open image is made to have a rounded corner frame.
The physical way of doing things that I’m tryingto translate would be
Select all
Modify Border by 20 pixels
Inverse selection
Modify Selection > Feather by 5pix
Enter quick mask
Adjust with curves (points (0,227), (255,227)
Exit Quick mask
convert background layer to a layer
apply the selection as a layer mask.

I would like to perform this without the use of GUI scripting and as little javascript from the JS listener plugin as possible.

I’ve gotten thus far:

set Slect2Channel to "var idDplc = charIDToTypeID( "Dplc" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc3.putReference( idnull, ref1 );
var idNm = charIDToTypeID( "Nm " );
desc3.putString( idNm, "Border Channel" );
executeAction( idDplc, desc3, DialogModes.NO );
"

– enable GUI short name for Photoshop in case I need to do key commands
tell application “System Events”
set PSProcess to name of application id “com.adobe.Photoshop”
end tell

tell application “Adobe Photoshop CS4”
activate
change mode of current document to RGB

-- make sure the document is flattened
tell current document
	try
		flatten
	end try
	
	-- make the background layer into a regular layer
	if background layer exists then
		set background layer of art layer 1 to false
	end if
	
end tell

set z to 0.1
tell application "Adobe Photoshop CS4"
	activate
	tell current document
		set theWidth to width
		set theheight to height
		select region {{z, z}, {theWidth - z, z}, {theWidth - z, theheight - z}, {z, theheight - z}} feather amount 10 without antialiasing
		
                   -- I didn't want to but I can not figure out how to convert a selection to a channel
		do javascript Slect2Channel show debugger on runtime error
		
		(* I can't seem to be able to select a channel and then apply  a curve
                   adjust channel "Border Channel" of the current document using curves ¬
			with options {class:curves, curve points:{{0, 0}, {255, 147}}}

*)
end tell

end tell

end tell

Any help is much appreciated.

Moved the topic to the appropriate forum :slight_smile:

Almost never used the quick mask feature of Photoshop (isn’t it just a GUI thing). Could you explain what the curve is adjusting as I have run through your list and all I end up with is a floating layer that has a slightly rounded corner to a feathered edge in a masked layer. Am I getting this correct? I don’t have CS4 so may be Im overlooking something too.

Why not just use a photoshop action?

Mark, from reading the process that is exactly what he is going for.

Jerome, the only if/else logic I could see was with regard to possible layers otherwise I would agree with you and use an action. I tried using several images to see how the use of a curve would effect the selection edge feathering and could not work that part out. In CS2 I have no scripting access to layer masks so would use script listener for that part. The 4 options are in the sub’s comments.

tell application "Adobe Photoshop CS2"
	set User_Notifiers to notifiers enabled
	set User_Rulers to ruler units of settings
	set User_Dialogs to display dialogs
	set notifiers enabled to false
	set ruler units of settings to pixel units
	set display dialogs to never
	set foreground color to {class:RGB color, red:0.0, green:0.0, blue:0.0}
	set background color to {class:RGB color, red:255.0, green:255.0, blue:255.0}
end tell
--
tell application "Adobe Photoshop CS2"
	activate
	-- open The_File
	set Doc_Ref to the current document
	tell Doc_Ref
		(*if bits per channel is sixteen then
			set bits per channel to eight
		end if*)
		if mode is not RGB then
			change mode to RGB
		end if
		if (count of art layers) > 1 or (count of layer sets) > 0 ¬
			or ((count of art layers) is 1 and not background layer of layer 1) then flatten
		(*set Pixel_Height to height
		set Pixel_Width to width*)
		select all
		select border selection width 20
		invert selection
		smooth selection radius 5
		set background layer of layer 1 to false
		my Layer_Mask_Make(Doc_Ref, "RvlS")
	end tell
end tell
--
tell application "Adobe Photoshop CS2"
	set notifiers enabled to User_Notifiers
	set ruler units of settings to User_Rulers
	set display dialogs to User_Dialogs
end tell
--
on Layer_Mask_Make(Doc_Ref, Mask_Ref)
	-- Mask_Ref = RvlA, HdAl, RvlS, HdSl
	tell application "Adobe Photoshop CS2"
		tell Doc_Ref
			do javascript "Layer_Masks(); function Layer_Masks() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); desc01.putClass( cTID('Nw  '), cTID('Chnl') ); var ref01 = new ActionReference(); ref01.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Msk ') ); desc01.putReference( cTID('At  '), ref01 ); desc01.putEnumerated( cTID('Usng'), cTID('UsrM'), cTID('" & Mask_Ref & "') ); executeAction( cTID('Mk  '), desc01, DialogModes.NO );};" show debugger on runtime error
		end tell
	end tell
end Layer_Mask_Make

There is no need for the if statement, just adding a flatten at the beginning of the action should take care of that since all images need to be flattened. Works like a dream even on an image that is already flattened. The only problem I see is that the curves values are not accepted by PS CS3, they need to be (0,223), (255,227) or (0,227), (255,231) for the curves to work properly.

Thanks for all the feed back.
The reason I do not want to use an action is, I don’t want to have to send that file and install it on multiple machines as well. If the action is not loaded the script would not run properly.

The reason I use the quick mask option is to quickly curve from the feathered rounded corners to a sharp edge. This can be done in a channel or a layer mask but I can’t seem to get the selection I create turned into either, and apply a curve to that mask/channel/quick mask.

The curve is just the black point pulled towards center and the white point pulled towards center. I might have my digits transposed. I figure, if need to I could later add a prompt for someone to add points that they want for a curve.

I was only tying to explain what I would do If I were to create an PS action. It seems when you work with applescripting PS you have to do some work around for things that just come common like quick mask.

Mark,

I ran the script you posted with CS4 and I get a runtime error from the javascript portion.
Adobe Extended Script Toolkit launches and displays

Layer_Masks(); function Layer_Masks() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); desc01.putClass( cTID('Nw '), cTID(‘Chnl’) ); var ref01 = new ActionReference(); ref01.putEnumerated( cTID(‘Chnl’), cTID(‘Chnl’), cTID('Msk ') ); desc01.putReference( cTID('At '), ref01 ); desc01.putEnumerated( cTID(‘Usng’), cTID(‘UsrM’), cTID(‘RvlS’) ); executeAction( cTID('Mk '), desc01, DialogModes.NO );};

One question I have is the variable line 32 “RvIS” is used but I can not figure out what this does

I am not sure why that would be. May be there is something different in your documents current state that the script listener function does not like. Works just fine for me. I have added some extra syntax to see if it helps. Plus how to load and save selections to channels you will need to change to your curve points.

tell application "Adobe Photoshop CS2"
	set User_Notifiers to notifiers enabled
	set User_Rulers to ruler units of settings
	set User_Dialogs to display dialogs
	set notifiers enabled to false
	set ruler units of settings to pixel units
	set display dialogs to never
	set foreground color to {class:RGB color, red:0.0, green:0.0, blue:0.0}
	set background color to {class:RGB color, red:255.0, green:255.0, blue:255.0}
end tell
--
tell application "Adobe Photoshop CS2"
	activate
	set Doc_Ref to the current document
	tell Doc_Ref
		if mode is not RGB then
			change mode to RGB
		end if
		if (count of art layers) > 1 or (count of layer sets) > 0 ¬
			or ((count of art layers) is 1 and not background layer of layer 1) then flatten
		
		set Frame_Select to make new channel with properties ¬
			{name:"Frame", kind:selected area channel}
		set the current channels to channel "Frame"
		select all
		select border selection width 20
		invert selection
		smooth selection radius 5
		fill selection with contents {class:RGB color, red:0, green:0, blue:0}
		adjust layers using curves with options ¬
			{class:curves, curve points:{{0, 0}, {64, 46.08}, {128, 128}, {192, 217.6}, {255, 255}}}
		set current channels to component channels
		load selection from channel "Frame"
		set background layer of layer 1 to false
		my Layer_Mask_Make(Doc_Ref, "RvlS")
		set current channels to component channels
		delete channel "Frame"
	end tell
end tell
--
tell application "Adobe Photoshop CS2"
	set notifiers enabled to User_Notifiers
	set ruler units of settings to User_Rulers
	set display dialogs to User_Dialogs
end tell
--
on Layer_Mask_Make(Doc_Ref, Mask_Ref)
	-- Mask_Ref = RvlA, HdAl, RvlS, HdSl
	tell application "Adobe Photoshop CS2"
		tell Doc_Ref
			do javascript "Layer_Masks(); function Layer_Masks() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); desc01.putClass( cTID('Nw  '), cTID('Chnl') ); var ref01 = new ActionReference(); ref01.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Msk ') ); desc01.putReference( cTID('At  '), ref01 ); desc01.putEnumerated( cTID('Usng'), cTID('UsrM'), cTID('" & Mask_Ref & "') ); executeAction( cTID('Mk  '), desc01, DialogModes.NO );};" show debugger on runtime error
		end tell
	end tell
end Layer_Mask_Make

I am able to call the same handler and use the 4 options the variable “RvIS” should be Reveal Selection, “HdSI” should be Hide Selection, “RvlA” Reveal All, “HdAl” Hide All

With some of your help Mark I came up with this:

tell application "Adobe Photoshop CS4"
	set User_Notifiers to notifiers enabled
	set User_Rulers to ruler units of settings
	set User_Dialogs to display dialogs
	set notifiers enabled to false
	set ruler units of settings to pixel units
	set display dialogs to never
	set foreground color to {class:RGB color, red:0.0, green:0.0, blue:0.0}
	set background color to {class:RGB color, red:255.0, green:255.0, blue:255.0}
end tell
--
set z to 0.1

tell application "Adobe Photoshop CS4"
	activate
	set Doc_Ref to the current document
	tell Doc_Ref
		if mode is not RGB then
			change mode to RGB
		end if
		if (count of art layers) > 1 or (count of layer sets) > 0 ¬
			or ((count of art layers) is 1 and not background layer of layer 1) then flatten
		
		set Frame_Select to make new channel with properties ¬
			{name:"Frame", kind:selected area channel}
		set the current channels to channel "Frame"
		select all
		
		set theWidth to width
		set theheight to height
		select region {{z, z}, {theWidth - z, z}, {theWidth - z, theheight - z}, {z, theheight - z}} feather amount 20 without antialiasing
		
		fill selection with contents {class:RGB color, red:0, green:0, blue:0}
		deselect
		
		adjust layers using curves with options ¬
			{class:curves, curve points:{{116, 0}, {134, 255}}}
		
		set current channels to component channels
		load selection from channel "Frame"
		
		-- make the background layer into a regular layer
		if background layer exists then
			set background layer of art layer 1 to false
		end if
		invert selection
		clear
		deselect
	end tell
end tell

please confirm that this works. If there is any redundancy or ways to clean up the code, it is much appreciated.