[Photoshop Scripting] Error codes mismatch depending on layer kind

  • 1
  • Problem
  • Updated 6 years ago
  • (Edited)
via scripting if I try to delete a nonexistent layer mask I obviously get an error (as expected).
Strangely enough either the error message and code differ whether the layer is a:

  1. bitmap: "Error #25920 - General Photoshop error occurred. This functionality may not be available in this version of Photoshop. The command “Delete” is not currently available."

  2. adjustment layer: "Error #8007 - User cancelled the operation."

I find the first one to make perfect sense, while the second is just a debugging PITA.

Please find below the code (to run on layers without layer masks in order to fire the error).

Davide Barranca

var s2t = function(stringID) {
return app.stringIDToTypeID(stringID);

// Delete a Layer Mask
var deleteLayerMask = function(layer) {
var d, layerName, r;
layerName = (layer != null ? layer.name : app.activeDocument.activeLayer.name);
d = new ActionDescriptor();
r = new ActionReference();
r.putEnumerated(s2t('channel'), s2t('channel'), s2t('mask'));
r.putName(s2t('layer'), layerName);
d.putReference(s2t('target'), r);
return executeAction(s2t('delete'), d, DialogModes.NO);

try {
deleteLayerMask ();
} catch(e) {
alert(e.message + "\n" + e.number);

Photo of Davide Barranca

Davide Barranca

  • 21 Posts
  • 3 Reply Likes
  • puzzled

Posted 6 years ago

  • 1

Be the first to post a reply!