Help modifying an existing script?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: xbytor, DavideBarranca, Paul MR

Jono
Posts: 1
Joined: Thu Oct 26, 2017 5:59 pm

Help modifying an existing script?

Postby Jono » Sat Oct 13, 2018 9:21 am

I have an existing script (thanks to other people helping me put it together), I've added it to the bottom of this post.
It grabs a RGB Hex colour copied to the clipboard and applies that colour as a colour overlay layer style to the selected layer.


I found a new script that adds a fill layer with a specified colour and was hoping to do a similar thing with it.

If possible I want it to grab the RGB Hex colour from the clipboard and use that as the colour for the fill layer (also setting the name of the layer to "Background" and creating the fill layer at the bottom).

I've tried modifying the new script myself, but don't know enough JavaScript and haven't managed to do it.Is something like that possible with the script below?

(Script I'd like to modify)

Code: Select all

tell application id "com.adobe.Photoshop"
activate
tell current document
do javascript "makeSolidFill (234, 34, 12); // Enter number here for color or use variables to set color
removeMask ()

function makeSolidFill(redC,greenC,blueC){
// ========================================
var idMk = charIDToTypeID( 'Mk ' );
var desc15 = new ActionDescriptor();
var idnull = charIDToTypeID( 'null' );
var ref4 = new ActionReference();
var idcontentLayer = stringIDToTypeID( 'contentLayer' );
ref4.putClass( idcontentLayer );
desc15.putReference( idnull, ref4 );
var idUsng = charIDToTypeID( 'Usng' );
var desc16 = new ActionDescriptor();
var idType = charIDToTypeID( 'Type' );
var desc17 = new ActionDescriptor();
var idClr = charIDToTypeID( 'Clr ' );
var desc18 = new ActionDescriptor();
var idRd = charIDToTypeID( 'Rd ' );
desc18.putDouble( idRd, redC); // Red variable
var idGrn = charIDToTypeID( 'Grn ' );
desc18.putDouble( idGrn, greenC); // Green variable
var idBl = charIDToTypeID( 'Bl ' );
desc18.putDouble( idBl, blueC ); // Blue variable
var idRGBC = charIDToTypeID( 'RGBC' );
desc17.putObject( idClr, idRGBC, desc18 );
var idsolidColorLayer = stringIDToTypeID( 'solidColorLayer' );
desc16.putObject( idType, idsolidColorLayer, desc17 );
var idcontentLayer = stringIDToTypeID( 'contentLayer' );
desc15.putObject( idUsng, idcontentLayer, desc16 );
executeAction( idMk, desc15, DialogModes.NO );
}

function removeMask(){
var idDlt = charIDToTypeID( 'Dlt ' );
var desc21 = new ActionDescriptor();
var idnull = charIDToTypeID( 'null' );
var ref5 = new ActionReference();
var idChnl = charIDToTypeID( 'Chnl' );
var idChnl = charIDToTypeID( 'Chnl' );
var idMsk = charIDToTypeID( 'Msk ' );
ref5.putEnumerated( idChnl, idChnl, idMsk );
desc21.putReference( idnull, ref5 );
executeAction( idDlt, desc21, DialogModes.NO );
}" show debugger on runtime error
end tell
end tell



(Existing script I have that grabs the RGB Hex colour copied to the clipboard and applies that colour as a colour overlay layer style to the selected layer)

Code: Select all

set theColour to the clipboard

try
tell application id "com.adobe.Photoshop"
tell current document
do javascript "var c = new SolidColor();
c.rgb.hexValue = " & quoted form of theColour & "

app.activeDocument.suspendHistory('TMP', 'aaa()');
executeAction( charIDToTypeID( 'undo' ), undefined, DialogModes.NO );
executeAction( charIDToTypeID( 'PaFX' ), undefined, DialogModes.NO );
function aaa()
{
app.activeDocument.artLayers.add();
var idsetd = charIDToTypeID( 'setd' );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( 'null' );
var ref1 = new ActionReference();
var idPrpr = charIDToTypeID( 'Prpr' );
var idLefx = charIDToTypeID( 'Lefx' );
ref1.putProperty( idPrpr, idLefx );
var idLyr = charIDToTypeID( 'Lyr ' );
var idOrdn = charIDToTypeID( 'Ordn' );
var idTrgt = charIDToTypeID( 'Trgt' );
ref1.putEnumerated( idLyr, idOrdn, idTrgt );
desc9.putReference( idnull, ref1 );
var idT = charIDToTypeID( 'T ' );
var desc10 = new ActionDescriptor();
var idScl = charIDToTypeID( 'Scl ' );
var idPrc = charIDToTypeID( '#Prc' );
desc10.putUnitDouble( idScl, idPrc, 100.000000 );
var idSoFi = charIDToTypeID( 'SoFi' );
var desc11 = new ActionDescriptor();
var idenab = charIDToTypeID( 'enab' );
desc11.putBoolean( idenab, true );
var idpresent = stringIDToTypeID( 'present' );
desc11.putBoolean( idpresent, true );
var idshowInDialog = stringIDToTypeID( 'showInDialog' );
desc11.putBoolean( idshowInDialog, true );
var idMd = charIDToTypeID( 'Md ' );
var idBlnM = charIDToTypeID( 'BlnM' );
var idNrml = charIDToTypeID( 'Nrml' );
desc11.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( 'Clr ' );
var desc12 = new ActionDescriptor();
var idRd = charIDToTypeID( 'Rd ' );
desc12.putDouble( idRd, c.rgb.red ); // RED
var idGrn = charIDToTypeID( 'Grn ' );
desc12.putDouble( idGrn, c.rgb.green ); // GREEN
var idBl = charIDToTypeID( 'Bl ' );
desc12.putDouble( idBl, c.rgb.blue ); // BLUE
var idRGBC = charIDToTypeID( 'RGBC' );
desc11.putObject( idClr, idRGBC, desc12 );
var idOpct = charIDToTypeID( 'Opct' );
var idPrc = charIDToTypeID( '#Prc' );
desc11.putUnitDouble( idOpct, idPrc, 100.000000 );
var idSoFi = charIDToTypeID( 'SoFi' );
desc10.putObject( idSoFi, idSoFi, desc11 );
var idLefx = charIDToTypeID( 'Lefx' );
desc9.putObject( idT, idLefx, desc10 );
executeAction( idsetd, desc9, DialogModes.NO );
executeAction( charIDToTypeID( 'CpFX' ), undefined, DialogModes.NO );
}" show debugger on runtime error
end tell
activate
end tell
end try

Return to “Help Me”

Who is online

Users browsing this forum: No registered users and 6 guests