• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help with events listening in HTML panel script

Participant ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hey there,

I'm currently working on a HTML panel for Photoshop. I'm having trouble with the EventListener. Well, with one particular event, the "applyLocking" one. This should fire when you change the locking status of a layer.

 

I already have an event listenner setup (using csInterface and "com.adobe.PhotoshopJSONCallback", and it works just fine with most events I listen to, but for some reasons, the "applyLocking" works only alf the time...

 

At first, I tried using static events TypeID. I had seen a few example around with this method... So, I declared my events like this :

 

var eventMake = 1298866208; // "Mk " *****
var eventDelete = 1147958304; // "Delete" *****
var eventPlay = 1349286176; // "Ply " 
var eventSelect = 1936483188; // "slct" 
var eventSet = 1936028772; // "setd"
var eventMerge = 1299343154; // "Mrg2" *****
var eventRename = 1382968608; // "Rnm " 
var eventMove = 1836021349; // "move" *****
var eventShow = 1399355168; // "Shw " 
var eventHide = 1214521376; // "Hd " 
var eventDuplicate = 1148218467; // "duplicate" ***** 
var eventPaste = 1885434740; // "paste" *****
var eventLock = 406; // lock


... and then passed those to my CSEvent().data. Gave it a try and it worked flawlessly.

But then... I read that TypeIDs were not "always" the same... so I rebooted PS and gave it another try. The "lock" event didn't fire.

 

I then made adjustments to pass stringIDs and charIDs instead of the hardcoded TypeIDs. I noticed that that the "applyLocking" stringID was now converted to "410".

 

So far so good... but I then realised that even if I used the stringIDs, I got problem with the lock event. Sometimes it works, sometimes it doesn't. And I just can't figure out what is going on.

 

Of course, I noticed that the "applyLocking" TypeID (406 or 410) is kinda strange when compared to other event TypeIDs. All the other ones I tried are 10-digits numbers...

 

The ScriptListeninng plugins really spits out a "applyLocking" event when I use the locking functions... but maybe that's not what I should be listenning for ?

 

You guys have any clues ?

 

Working on PS2020, in MacOS High Sierra.


Thanks a lot !

JK.

 

TOPICS
Actions and scripting

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hi,

The list of events that I have does not have any event for locking. Here is the list

 

PSEvent._3DTRANSFORM = "1415861280";
PSEvent.AVERAGE = "1098281575";
PSEvent.APPLY_STYLE = "1095988345";
PSEvent.ASSERT = "1098084980";
PSEvent.ACCENTED_EDGES = "1097032517";
PSEvent.ADD = "1097098272";
PSEvent.ADD_NOISE = "1097092723";
PSEvent.ADD_TO = "1097098324";
PSEvent.ALIGN = "1097623406";
PSEvent.ALL = "1097624608";
PSEvent.ANGLED_STROKES = "1097754451";
PSEvent.APPLY_IMAGE = "1097887817";
PSEvent.BAS_RELIEF = "1114853996";
PSEvent.BATCH = "1114923880";
PSEvent.BATCH_FROM_DROPLET = "1114923846";
PSEvent.BLUR = "1114403360";
PSEvent.BLUR_MORE = "1114403405";
PSEvent.BORDER = "1114793074";
PSEvent.BRIGHTNESS = "1114793795";
PSEvent.CANVAS_SIZE = "1131312723";
PSEvent.CHALK_CHARCOAL = "1130916931";
PSEvent.CHANNEL_MIXER = "1130917453";
PSEvent.CHARCOAL = "1130918499";
PSEvent.CHROME = "1130918509";
PSEvent.CLEAR = "1131177330";
PSEvent.CLOSE = "1131180832";
PSEvent.CLOUDS = "1131177075";
PSEvent.COLOR_BALANCE = "1131180610";
PSEvent.COLOR_HALFTONE = "1131180616";
PSEvent.COLOR_RANGE = "1131180626";
PSEvent.COLORED_PENCIL = "1131180624";
PSEvent.CONTE_CRAYON = "1131312195";
PSEvent.CONTRACT = "1131312227";
PSEvent.CONVERT_MODE = "1131312717";
PSEvent.COPY = "1668247673";
PSEvent.COPY_EFFECTS = "1131431512";
PSEvent.COPY_MERGED = "1131444557";
PSEvent.COPY_TO_LAYER = "1131435084";
PSEvent.CRAQUELURE = "1131573612";
PSEvent.CREATE_DROPLET = "1131574340";
PSEvent.CROP = "1131573104";
PSEvent.CROSSHATCH = "1131574120";
PSEvent.CRYSTALLIZE = "1131574132";
PSEvent.CURVES = "1131574899";
PSEvent.CUSTOM = "1131639917";
PSEvent.CUT = "1668641824";
PSEvent.CUT_TO_LAYER = "1131697228";
PSEvent.CUTOUT = "1131683872";
PSEvent.DARK_STROKES = "1148349267";
PSEvent.DE_INTERLACE = "1148089458";
PSEvent.DEFINE_PATTERN = "1147563600";
PSEvent.DEFRINGE = "1147564647";
PSEvent.DELETE = "1147958304";
PSEvent.DESATURATE = "1148417140";
PSEvent.DESELECT = "1148415075";
PSEvent.DESPECKLE = "1148416099";
PSEvent.DIFFERENCE_CLOUDS = "1147564611";
PSEvent.DIFFUSE = "1147564832";
PSEvent.DIFFUSE_GLOW = "1147564871";
PSEvent.DISABLE_LAYER_FX = "1684825720";
PSEvent.DISPLACE = "1148416108";
PSEvent.DISTRIBUTE = "1148417138";
PSEvent.DRAW = "1148346743";
PSEvent.DRY_BRUSH = "1148352834";
PSEvent.DUPLICATE = "1148218467";
PSEvent.DUST_AND_SCRATCHES = "1148417107";
PSEvent.EMBOSS = "1164796531";
PSEvent.EQUALIZE = "1165061242";
PSEvent.EXCHANGE = "1165517672";
PSEvent.EXPAND = "1165521006";
PSEvent.EXPORT = "1165521010";
PSEvent.EXTRUDE = "1165522034";
PSEvent.FACET = "1180922912";
PSEvent.FADE = "1180787813";
PSEvent.FEATHER = "1182034034";
PSEvent.FIBERS = "1180856947";
PSEvent.FILL = "1181491232";
PSEvent.FILM_GRAIN = "1181510983";
PSEvent.FILTER = "1181512818";
PSEvent.FIND_EDGES = "1181639749";
PSEvent.FLATTEN_IMAGE = "1181512777";
PSEvent.FLIP = "1181510000";
PSEvent.FRAGMENT = "1181902701";
PSEvent.FRESCO = "1181905763";
PSEvent.GAUSSIAN_BLUR = "1198747202";
PSEvent.GET = "1734702180";
PSEvent.GLASS = "1198289696";
PSEvent.GLOWING_EDGES = "1198290757";
PSEvent.GRADIENT = "1198679150";
PSEvent.GRADIENT_MAP = "1198673264";
PSEvent.GRAIN = "1198681632";
PSEvent.GRAPHIC_PEN = "1198678352";
PSEvent.GROUP = "1198682188";
PSEvent.GROW = "1198681975";
PSEvent.HALFTONE_SCREEN = "1215063635";
PSEvent.HIDE = "1214521376";
PSEvent.HIGH_PASS = "1214736464";
PSEvent.HSBHSL = "1215521360";
PSEvent.HUE_SATURATION = "1213428850";
PSEvent.IMAGE_SIZE = "1231906643";
PSEvent.IMPORT = "1231908978";
PSEvent.INK_OUTLINES = "1231973199";
PSEvent.INTERSECT = "1231975538";
PSEvent.INTERSECT_WITH = "1231975511";
PSEvent.INVERSE = "1231976051";
PSEvent.INVERT = "1231976050";
PSEvent.LENS_FLARE = "1282306886";
PSEvent.LEVELS = "1282829427";
PSEvent.LIGHTING_EFFECTS = "1281845317";
PSEvent.LINK = "1282304800";
PSEvent.MAKE = "1298866208";
PSEvent.MAXIMUM = "1299737888";
PSEvent.MEDIAN = "1298427424";
PSEvent.MERGE_LAYERS = "1299343154";
PSEvent.MERGE_LAYERS_OLD = "1299343180";
PSEvent.MERGE_SPOT_CHANNEL = "1297313908";
PSEvent.MERGE_VISIBLE = "1299343190";
PSEvent.MEZZOTINT = "1299870830";
PSEvent.MINIMUM = "1299082528";
PSEvent.MOSAIC = "1299407648";
PSEvent.MOSAIC_PLUGIN = "1299407700";
PSEvent.MOTION_BLUR = "1299476034";
PSEvent.MOVE = "1836021349";
PSEvent.NTSCCOLORS = "1314149187";
PSEvent.NEON_GLOW = "1313303671";
PSEvent.NEXT = "1316516896";
PSEvent.NOTE_PAPER = "1316245618";
PSEvent.NOTIFY = "1316251257";
PSEvent.OCEAN_RIPPLE = "1331916370";
PSEvent.OFFSET = "1332114292";
PSEvent.OPEN = "1332768288";
PSEvent.PAINT = "1349415968";
PSEvent.PAINT_DAUBS = "1349416004";
PSEvent.PALETTE_KNIFE = "1349284939";
PSEvent.PASTE = "1885434740";
PSEvent.PASTE_EFFECTS = "1348552280";
PSEvent.PASTE_INTO = "1349743689";
PSEvent.PASTE_OUTSIDE = "1349743695";
PSEvent.PATCHWORK = "1349804904";
PSEvent.PHOTOCOPY = "1349022819";
PSEvent.PINCH = "1349411688";
PSEvent.PLACE = "1349280544";
PSEvent.PLASTER = "1349284724";
PSEvent.PLASTIC_WRAP = "1349284695";
PSEvent.PLAY = "1349286176";
PSEvent.POINTILLIZE = "1349416044";
PSEvent.POLAR = "1349284384";
PSEvent.POSTER_EDGES = "1349743685";
PSEvent.POSTERIZE = "1349743730";
PSEvent.PREVIOUS = "1349678707";
PSEvent.PRINT = "1349676660";
PSEvent.PROFILE_TO_PROFILE = "1349674580";
PSEvent.PURGE = "1349674853";
PSEvent.QUIT = "1903520116";
PSEvent.RADIAL_BLUR = "1382313026";
PSEvent.RASTERIZE = "1383298162";
PSEvent.RASTERIZE_TYPE_SHEET = "1383298132";
PSEvent.REMOVE_BLACK_MATTE = "1382905410";
PSEvent.REMOVE_LAYER_MASK = "1382905420";
PSEvent.REMOVE_WHITE_MATTE = "1382905431";
PSEvent.RENAME = "1382968608";
PSEvent.REPLACE_COLOR = "1383099459";
PSEvent.RESET = "1383294324";
PSEvent.RETICULATION = "1383359340";
PSEvent.REVERT = "1383494260";
PSEvent.RIPPLE = "1383099493";
PSEvent.ROTATE = "1383363685";
PSEvent.ROUGH_PASTELS = "1382508624";
PSEvent.SAVE = "1935767141";
PSEvent.SELECT = "1936483188";
PSEvent.SELECTIVE_COLOR = "1399612227";
PSEvent.SET = "1936028772";
PSEvent.SHARPEN_EDGES = "1399353925";
PSEvent.SHARPEN = "1399353968";
PSEvent.SHARPEN_MORE = "1399353933";
PSEvent.SHEAR = "1399353888";
PSEvent.SHOW = "1399355168";
PSEvent.SIMILAR = "1399680114";
PSEvent.SMART_BLUR = "1399681602";
PSEvent.SMOOTH = "1399682152";
PSEvent.SMUDGE_STICK = "1399678035";
PSEvent.SOLARIZE = "1399616122";
PSEvent.SPATTER = "1399878688";
PSEvent.SPHERIZE = "1399875698";
PSEvent.SPLIT_CHANNELS = "1399876675";
PSEvent.SPONGE = "1399877223";
PSEvent.SPRAYED_STROKES = "1399878227";
PSEvent.STAINED_GLASS = "1400139335";
PSEvent.STAMP = "1400139120";
PSEvent.STOP = "1400139632";
PSEvent.STROKE = "1400140395";
PSEvent.SUBTRACT = "1398961266";
PSEvent.SUBTRACT_FROM = "1398961222";
PSEvent.SUMIE = "1399679333";
PSEvent.TAKE_MERGED_SNAPSHOT = "1416318322";
PSEvent.TAKE_SNAPSHOT = "1416319854";
PSEvent.TEXTURE_FILL = "1417180230";
PSEvent.TEXTURIZER = "1417180282";
PSEvent.THRESHOLD = "1416131187";
PSEvent.TILES = "1416393504";
PSEvent.TORN_EDGES = "1416785477";
PSEvent.TRACE_CONTOUR = "1416782659";
PSEvent.TRANSFORM = "1416785510";
PSEvent.TRAP = "1416782192";
PSEvent.TWIRL = "1417114220";
PSEvent.UNDERPAINTING = "1433298034";
PSEvent.UNDO = "1970168943";
PSEvent.UNGROUP = "1433298802";
PSEvent.UNLINK = "1433300075";
PSEvent.UNSHARP_MASK = "1433301837";
PSEvent.VARIATIONS = "1450341486";
PSEvent.WAIT = "1466001780";
PSEvent.WATER_PAPER = "1467249232";
PSEvent.WATERCOLOR = "1467249251";
PSEvent.WAVE = "1466005093";
PSEvent.WIND = "1466852384";
PSEvent.ZIG_ZAG = "1516722791";
PSEvent.BACK_LIGHT = "1113678668";
PSEvent.FILL_FLASH = "1181314117";
PSEvent.COLOR_CAST = "1131375685";
PSEvent.OPEN_UNTITLED = "1332768341";

 

But you said it is working on Mac. But how one event can have different id as 406 or 410?

 

Thanks

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

I know, it's weird.  At first, I really thought events would have a unique and constant TypeID, but it looks like it's not always the case.  I am really curious to know why the TypeID for "applyLocking" is a 3-digits number, and not a full 10-digits one like all the others...

 

One thing is for sure... It does work, from time to time... but I can't get my head around "why" it behaves that way.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Not the answer to your problem, but that might help: charIDToTypeID and stringIDToTypeID finder script!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hey thanks for that.  Looks like an interesting tool.  What does it do exactly... it tries to find every possible charID there is ?

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Yes, but as r-bin proved it doesn't finds all of them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Yes that's correct, It does not give for all and I think I tried yesterday, it does not give for locking.

 

Thanks

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

It is only necessary to use the stringIDToTypeID function. It is acceptable (but not advisable) to use digital identifiers instead of charDToTypeID.
Those stringIDs that do not have charIDs are exactly dynamic. And on different Photoshop or under different conditions, they can have different numerical values.

The simplest example.
Restart Photoshop and do nothing, run the script.
alert(stringIDToTypeID("SaveForWeb"));

Remember the value.

Restart Photoshop. Create a file. Turn the layer into a smart object and apply a Liquify filter to it (do any distortion). After that, run the script and compare the new number with the old one.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

Hi,

Thanks for sharing this, something new for me atleast. Therefore should we use 'stringIDToTypeID', so that it always remains same?

 

Thanks

 

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

You should use something like this

if (enentID == stringIDToTypeID("SaveForWeb")) { /*do smthng*/ }

but not
if (enentID == 123456) { /*do smthng*/ }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Makes sense.

 

That being said, I remember thinking "this is probably more efficient" when I saw examples of code with the eventID hardcoded...  How much overhead the "stringIDToTypeID" introduce into a script ?

 

Since I am listening to quite a bunch of events, do I make my script "slower" (even just a very little) by calling stringIDToTypeID() so many times ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

That's right, now I remember too those numbers can differ for another Photoshop sessions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 14, 2020 May 14, 2020

Copy link to clipboard

Copied

Here's an update.

 

I've built myself a new testing panel.  All it does is listen to the very same events, and print out the event.data (the JSON string) that gets sent back by com.adobe.PhotoshopJSONCallback.  The whole EventListenning part is the same exact piece of code.

 

On this "testing" panel, it feels like the "applyLocking" events gets fired every single time.  The JSON string changes each and every time I lock or unlock a layer.  It works if I use "applyLocking" or if I use "406" like I did before.

 

Now... for some reasons, it doesn't work at all in my other script.  It's getting frustrating.  I have both panels open... I lock the layer... I can see the "testing" panel update, but not the real one.  What is going on ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

LATEST

Try to use character code 456.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines