Skip to main content
Participating Frequently
August 28, 2012
Question

artLayer selected event?

  • August 28, 2012
  • 3 replies
  • 4396 views

Hey guy, I'm just getting into CS Extention Builder, so still a bit of a n00b with this, and havn't been able to find anything about what I'm needing in the docs, forums or googling around.

How can I setup an event that gets fired when the user changes their active layer?

This topic has been closed for replies.

3 replies

Participating Frequently
September 2, 2012

Thank you very much for your quick and detailed answers.

I'm still getting my head around this, although I'm thinking this

method may be overkill for what I'm trying to do. Both in

complexity and load on photoshop.

My use for this was really just a user friendly nicety, that will

display the selected layer in a text label to indicate which layer

the plugin controls will process.

I am definatly bookmarking this thread for future reference,

And I will post more details about what I'm doing and how

it works out in their thread when I get a little further along.

Thanks Much Guys!

Tom Ruark
Inspiring
August 28, 2012

The simple answer is this. I have a bunch of interesting events commented out in the Script Events Manager.jsx file.

//  Class IDs related to event select

          inObject['events'].push( new EventData( 'Select Layer', 'slct', 'Lyr ' ) );

But this does not solve all of them. If you open/select/close a document for example you will get a new layer selected. If you make a layer, that menu item is commented out as well, you will have a new layer selected.

If a user runs an action or a script the current layer might be switched. There are a lot of edge cases unfortunately.

JJMack
Community Expert
Community Expert
August 28, 2012

Un commenting most of the event Tom has commented ouu in the Script Events Manager script woul give you a much latger predefined list of events.

JJMack
JJMack
Community Expert
Community Expert
August 28, 2012

In Photoshop Scripting guide there is some code you can use the find out the codes the scriptlistner uses for events and in the Photoshop Java Scripting guide there is a list of IDs in Appendex A,  The Script event manager has some predefined events you can set event handlers for and you can add event to its list.  There may not be a ID for change active layer itself you may need to use some other event like select  and see if its select layer.  I do not know for I have never tried to add an event that was not allready in the Script Event managers list.  You need to read the two scripting guides on the subject of events, script event manager and the scriptlistener.  I beleive the information you need is in there,

JJMack
Participating Frequently
August 28, 2012

yes, that was not in the list of events,  thats what brought me here

JJMack
Community Expert
Community Expert
August 28, 2012

In the scripting guide you should see these:

how to set up a handler

app.notifiersEnabled = true

var eventFile = new File(app.path +

"/Presets/Scripts/Event Scripts Only/Welcome.jsx")

app.notifiers.add("Opn ", eventFile)

and this:

Finding the event ID for the “Open Document” event

1. Make sure that the ScriptListener plug in is installed.

2. Open Photoshop, then open a document.

3. Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log

file. In the JavaScript version of the file, you will see code that looks something like this at the end of

the file, everything below the row of equal signs the log of the last action taken:

// =======================================================

var id14 = charIDToTypeID( "Opn " );

var desc5 = new ActionDescriptor();

var id15 = charIDToTypeID( "null" );

desc5.putPath( id15, new File( "C:\\Program Files\\Adobe\\Adobe Photoshop CS6\\

Samples\\Fish.psd" ) );

executeAction( id14, desc5, DialogModes.NO );

4. The executeAction method runs the action from a script, and it needs the event ID to identify which

action to take. The first argument, in this case id14, provides the event ID to the method. You can see

the variable id14 defined several lines earlier, and it shows that the event ID for the Open Document

action is "Opn ".

5. You can now use this event ID to set up event notification on Open Document from your scripts. In

JavaScript, for example:

var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx")

app.notifiers.add( "Opn ", eventFile)

Finding the event ID and class ID for the “New” event

1. Make sure that the ScriptListener plug in is installed.

2. Open Photoshop, then create a new document using File > New.

3. Next, create a new channel, using the Create New Channel icon on the Channels palette.

4. Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log

file. We have recorded two actions, so we are interested in looking at the last two sections in the file

that are delimited by the rows of equal signs. In the JavaScript log file, you will see code that looks

something like this:

CHAPTER 4: Action Manager Using ScriptListener to find event IDs and class IDs 82

// =======================================================

var id17 = charIDToTypeID( "Mk " );

var desc6 = new ActionDescriptor();

var id18 = charIDToTypeID( "Nw " );

var desc7 = new ActionDescriptor();

var id19 = charIDToTypeID( "Md " );

var id20 = charIDToTypeID( "RGBM" );

desc7.putClass( id19, id20 );

var id21 = charIDToTypeID( "Wdth" );

var id22 = charIDToTypeID( "#Rlt" );

desc7.putUnitDouble( id21, id22, 800.000000 );

var id23 = charIDToTypeID( "Hght" );

var id24 = charIDToTypeID( "#Rlt" );

desc7.putUnitDouble( id23, id24, 800.000000 );

var id25 = charIDToTypeID( "Rslt" );

var id26 = charIDToTypeID( "#Rsl" );

desc7.putUnitDouble( id25, id26, 72.000000 );

var id27 = stringIDToTypeID( "pixelScaleFactor" );

desc7.putDouble( id27, 1.000000 );

var id28 = charIDToTypeID( "Fl " );

var id29 = charIDToTypeID( "Fl " );

var id30 = charIDToTypeID( "Wht " );

desc7.putEnumerated( id28, id29, id30 );

var id31 = charIDToTypeID( "Dpth" );

desc7.putInteger( id31, 8 );

var id32 = stringIDToTypeID( "profile" );

desc7.putString( id32, "sRGB IEC61966-2.1" );

var id33 = charIDToTypeID( "Dcmn" );

desc6.putObject( id18, id33, desc7 );

executeAction( id17, desc6, DialogModes.NO );

// =======================================================

var id34 = charIDToTypeID( "Mk " );

var desc8 = new ActionDescriptor();

var id35 = charIDToTypeID( "Nw " );

var desc9 = new ActionDescriptor();

var id36 = charIDToTypeID( "ClrI" );

var id37 = charIDToTypeID( "MskI" );

var id38 = charIDToTypeID( "MskA" );

desc9.putEnumerated( id36, id37, id38 );

var id39 = charIDToTypeID( "Clr " );

var desc10 = new ActionDescriptor();

var id40 = charIDToTypeID( "Rd " );

desc10.putDouble( id40, 255.000000 );

var id41 = charIDToTypeID( "Grn " );

desc10.putDouble( id41, 0.000000 );

var id42 = charIDToTypeID( "Bl " );

desc10.putDouble( id42, 0.000000 );

var id43 = charIDToTypeID( "RGBC" );

desc9.putObject( id39, id43, desc10 );

var id44 = charIDToTypeID( "Opct" );

desc9.putInteger( id44, 50 );

var id45 = charIDToTypeID( "Chnl" );

desc8.putObject( id35, id45, desc9 );

executeAction( id34, desc8, DialogModes.NO );

5. The first section represents the scripting code to execute the “New Document” event. The second

section represents the scripting code for the “New Channel” event

6. The executeAction method for both of these actions takes an argument whose value is defined as

"Mk ". (See id17 and id34.) This is the event ID for the “New” action. This action also needs to know

what class to use, the class ID for the event.

7. The putObject method identifies the class the action operates on. The second argument to

putObject provides us with the class ID that we need. In the first action, id33 is defined as "Dcmn", in

the second action, id45 is defined as "Chnl". These provide our class IDs for Document and Channel,

respectively.

8. You can now use these event and class IDs to set up event notification on the New Document and New

Channel events from your scripts. In JavaScript, for example:

var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx")

app.notifiers.add("Mk ", eventFile, "Dcmn")

app.notifiers.add("Mk ", eventFile, "Chnl")

Appendix A: Event ID Codes

The following table lists events and their four-character ID codes or string identifiers for use with the

notifier object.

Note: Do not include single quotes ( ' ) with four-character IDs in your code. The single quotes are

used in this table to illustrate the placement of required spaces in codes that do not contain four

letters. However, string identifiers, which are longer than four characters, require double quotes in

the code.

Tip: If you can’t find the event you want to use for notification in this table, you can use ScriptListener to

determine the event ID code. See the ScriptListener documentation in the Action Manager chapter of

the Photoshop CS6 Scripting Guide.

Event 4-char ID or String

3DTransform 'TdT '

Average 'Avrg'

ApplyStyle 'ASty'

Assert 'Asrt'

AccentedEdges 'AccE'

Add 'Add '

AddNoise 'AdNs'

AddTo 'AddT'

Align 'Algn'

All 'All '

AngledStrokes 'AngS'

ApplyImage 'AppI'

BasRelief 'BsRl'

Batch 'Btch'

BatchFromDroplet 'BtcF'

Blur 'Blr '

BlurMore 'BlrM'

Border 'Brdr'

Brightness 'BrgC'

CanvasSize 'CnvS'

ChalkCharcoal 'ChlC'

ChannelMixer 'ChnM'

Charcoal 'Chrc'

Chrome 'Chrm'

Clear 'Cler'

Close 'Cls '

Clouds 'Clds'

ColorBalance 'ClrB'

ColorHalftone 'ClrH'

ColorRange 'ClrR'

ColoredPencil 'ClrP'

ContactSheet "0B71D221-F8CE-11d2-B21B-0008C75B322C"

ConteCrayon 'CntC'

Contract 'Cntc'

ConvertMode 'CnvM'

Copy 'copy'

CopyEffects 'CpFX'

CopyMerged 'CpyM'

CopyToLayer 'CpTL'

Craquelure 'Crql'

CreateDroplet 'CrtD'

Crop 'Crop'

Crosshatch 'Crsh'

Crystallize 'Crst'

Curves 'Crvs'

Custom 'Cstm'

Cut 'cut '

CutToLayer 'CtTL'

Cutout 'Ct '

DarkStrokes 'DrkS'

DeInterlace 'Dntr'

DefinePattern 'DfnP'

Defringe 'Dfrg'

Delete 'Dlt '

Desaturate 'Dstt'

Deselect 'Dslc'

Despeckle 'Dspc'

DifferenceClouds 'DrfC'

Diffuse 'Dfs '

DiffuseGlow 'DfsG'

DisableLayerFX 'dlfx'

Displace 'Dspl'

Distribute 'Dstr'

Draw 'Draw'

DryBrush 'DryB'

Duplicate 'Dplc'

DustAndScratches 'DstS'

Emboss 'Embs'

Equalize 'Eqlz'

Exchange 'Exch'

Expand 'Expn'

Export 'Expr'

Jumpto 'Jpto'

ExportTransparentImage "02879e00-cb66-11d1-bc43-0060b0a13dc4"

Extrude 'Extr'

Facet 'Fct '

Fade 'Fade'

Feather 'Fthr'

Fibers 'Fbrs'

Fill 'Fl '

FilmGrain 'FlmG'

Filter 'Fltr'

FindEdges 'FndE'

FitImage "3caa3434-cb67-11d1-bc43-0060b0a13dc4"

FlattenImage 'FltI'

Flip 'Flip'

Fragment 'Frgm'

Fresco 'Frsc'

GaussianBlur 'GsnB'

Get 'getd'

Glass 'Gls '

GlowingEdges 'GlwE'

Gradient 'Grdn'

GradientMap 'GrMp'

Grain 'Grn '

GraphicPen 'GraP'

Group 'GrpL'

Grow 'Grow'

HalftoneScreen 'HlfS'

Hide 'Hd '

HighPass 'HghP'

HSBHSL 'HsbP'

HueSaturation 'HStr'

ImageSize 'ImgS'

Import 'Impr'

InkOutlines 'InkO'

Intersect 'Intr'

IntersectWith 'IntW'

Inverse 'Invs'

Invert 'Invr'

LensFlare 'LnsF'

Levels 'Lvls'

LightingEffects 'LghE'

Link 'Lnk '

Make 'Mk '

Maximum 'Mxm '

Median 'Mdn '

MergeLayers 'Mrg2'

MergeLayersOld 'MrgL'

MergeSpotChannel 'MSpt'

MergeVisible 'MrgV'

Mezzotint 'Mztn'

Minimum 'Mnm '

ModeChange "8cba8cd6-cb66-11d1-bc43-0060b0a13dc4"

Mosaic 'Msc '

Mosaic_PLUGIN 'MscT'

MotionBlur 'MtnB'

Move 'move'

NTSCColors 'NTSC'

NeonGlow 'NGlw'

Next 'Nxt '

NotePaper 'NtPr'

Notify 'Ntfy'

Null typeNull

OceanRipple 'OcnR'

Offset 'Ofst'

Open 'Opn '

Paint 'Pnt '

PaintDaubs 'PntD'

PaletteKnife 'PltK'

Paste 'past'

PasteEffects 'PaFX'

PasteInto 'PstI'

PasteOutside 'PstO'

Patchwork 'Ptch'

Photocopy 'Phtc'

PicturePackage "4C1ABF40-DD82-11d2-B20F-0008C75B322C"

Pinch 'Pnch'

Place 'Plc '

Plaster 'Plst'

PlasticWrap 'PlsW'

Play 'Ply '

Pointillize 'Pntl'

Polar 'Plr '

PosterEdges 'PstE'

Posterize 'Pstr'

Previous 'Prvs'

Print 'Prnt'

ProfileToProfile 'PrfT'

Purge 'Prge'

Quit 'quit'

RadialBlur 'RdlB'

Rasterize 'Rstr'

RasterizeTypeSheet 'RstT'

RemoveBlackMatte 'RmvB'

RemoveLayerMask 'RmvL'

RemoveWhiteMatte 'RmvW'

Rename 'Rnm '

ReplaceColor 'RplC'

Reset 'Rset'

ResizeImage "1333cf0c-cb67-11d1-bc43-0060b0a13dc4"

Reticulation 'Rtcl'

Revert 'Rvrt'

Ripple 'Rple'

Rotate 'Rtte'

RoughPastels 'RghP'

Save 'save'

Select 'slct'

SelectiveColor 'SlcC'

Set 'setd'

SharpenEdges 'ShrE'

Sharpen 'Shrp'

SharpenMore 'ShrM'

Shear 'Shr '

Show 'Shw '

Similar 'Smlr'

SmartBlur 'SmrB'

Smooth 'Smth'

SmudgeStick 'SmdS'

Solarize 'Slrz'

Spatter 'Spt '

Spherize 'Sphr'

SplitChannels 'SplC'

Sponge 'Spng'

SprayedStrokes 'SprS'

StainedGlass 'StnG'

Stamp 'Stmp'

Stop 'Stop'

Stroke 'Strk'

Subtract 'Sbtr'

SubtractFrom 'SbtF'

Sumie 'Smie'

TakeMergedSnapshot 'TkMr'

TakeSnapshot 'TkSn'

TextureFill 'TxtF'

Texturizer 'Txtz'

Threshold 'Thrs'

Tiles 'Tls '

TornEdges 'TrnE'

TraceContour 'TrcC'

Transform 'Trnf'

Trap 'Trap'

Twirl 'Twrl'

Underpainting 'Undr'

Undo 'undo'

Ungroup 'Ungr'

Unlink 'Unlk'

UnsharpMask 'UnsM'

Variations 'Vrtn'

Wait 'Wait'

WaterPaper 'WtrP'

Watercolor 'Wtrc'

Wave 'Wave'

Wind 'Wnd '

ZigZag 'ZgZg'

BackLight 'BacL'

FillFlash 'FilE'

ColorCast 'ColE'

JJMack