Hi folks.
I am building a script to modify rapidly my aqua wallpaper including a quotation (or a TO DO list, or anything!).
Basically, i open the wallpaper file with photoshop, I add a text level with a quotation (I’ll build a cocoa framework to introduce the quote myself).
I’d like to add a “drop shadow” to the text layer (or other effects, I want to experiment).
Is it possible to manipulate the style of a layer, adding shadws etc. via AppleScript? Which classes do I have to manipulate?
Cheers,
Davide
I am wondering the same thing?
All the dictionary lists is:
apply layer style‚v
apply layer style art layer : the art layer object or objects to be operated upon
using text : name of the layer style to apply
However, I don’t see any reference to the types of styles to apply, such as overlay, stroke, drop shadow, etc.
I can call an action, but I would prefer not to do that.
If you don’t want to call an action then use the Photoshop’s Scriptlistener plug-in record setting a layer style and save the output as as a JavaScript function that you can call. Scriptlistener’s output is action manager code where you can edit the recorded options values. You don’t have direct access to action manager from AppleScript but you can use it through calling JavaScript. If you apply layer styles then you must apply all styles at once as each apply to layer wipes the styles that were there before.
set DropShadow to ¬
"function dropShadow() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc01 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( cTID('Prpr'), cTID('Lefx') );
ref1.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc01.putReference( cTID('null'), ref1 );
var desc02 = new ActionDescriptor();
desc02.putUnitDouble( cTID('Scl '), cTID('#Prc'), 100.000000 );
var desc03 = new ActionDescriptor();
desc03.putBoolean( cTID('enab'), true );
desc03.putEnumerated( cTID('Md '), cTID('BlnM'), cTID('Mltp') ); // Blend Mode
var desc04 = new ActionDescriptor();
desc04.putDouble( cTID('Rd '), 0.000000 ); // Red
desc04.putDouble( cTID('Grn '), 0.000000 ); // Green
desc04.putDouble( cTID('Bl '), 0.000000 ); // Blue
desc03.putObject( cTID('Clr '), cTID('RGBC'), desc04 );
desc03.putUnitDouble( cTID('Opct'), cTID('#Prc'), 75.000000 ); // Opacity
desc03.putBoolean( cTID('uglg'), true );
desc03.putUnitDouble( cTID('lagl'), cTID('#Ang'), 120.000000 ); // Angle
desc03.putUnitDouble( cTID('Dstn'), cTID('#Pxl'), 10.000000 ); // Distance
desc03.putUnitDouble( cTID('Ckmt'), cTID('#Pxl'), 0.000000 ); // Spread
desc03.putUnitDouble( cTID('blur'), cTID('#Pxl'), 5.000000 ); // Blur
desc03.putUnitDouble( cTID('Nose'), cTID('#Prc'), 0.000000 ); // Noise
desc03.putBoolean( cTID('AntA'), false );
var desc05 = new ActionDescriptor();
desc05.putString( cTID('Nm '), 'Linear' );
desc03.putObject( cTID('TrnS'), cTID('ShpC'), desc05 );
desc03.putBoolean( sTID('layerConceals'), true );
desc02.putObject( cTID('DrSh'), cTID('DrSh'), desc03 );
desc01.putObject( cTID('T '), cTID('Lefx'), desc02 );
executeAction( cTID('setd'), desc01, DialogModes.NO );
}
dropShadow();"
tell application "Adobe Photoshop CS2"
activate
set Doc_Ref to the current document
tell Doc_Ref
-- Make sure you have an active layer
set current layer to (first art layer whose kind is text layer)
do javascript DropShadow show debugger on runtime error
end tell
end tell
Put a quick example of the output so you can see where to edit the values. I normally would put these scriptlistener functions into handlers to call but you should get the general idea.
As I recall the apply layer style requires a layer style in the styles pallet. You can have any number of effects preset in a layer style, so you could have one set up with a stroke and a drop shadow, apply that to the layer and you get the desired effect.
Marks script listener code access the drop shadow directly so that you could adjust it’s properties in the script. This is a more flexible approach, but if you can set up a predefined layer style(s) to meet your needs the apply layer style should work fine.
Thank you Mark and Jerome, both of your suggestions are excellent. I am slightly familiar with using Photoshop’s Scriptlistener, and would have never thought about using this. And calling pre-defined styles opens some other doors to ideas in the future.
FWIW, my question originated because I had my script calling an action, and somebody removed the action from their palette. I feel much safer that they will not remove the js that is tucked away on their local machine.
Any idea why Adobe has not expanded its AppleScript API to include direct control over applying layer styles/effects?