Dev Tool Snippets (for Webpack) - adobe-photoshop/spaces-design GitHub Wiki
The following DevTools snippets can make working with Spaces/Design Space easier.
Instructions for installing and using snippets are here.
all-events.js
This snippet will print out the command name and action descriptors of events being played in native Photoshop.
(function () {
__LOG_UTIL__.enableAll();
__PS_ADAPTER__.ps.descriptor.on("all", function (event, obj) {
__LOG_UTIL__.debug("[Descriptor]: " + event + JSON.stringify(obj, null, " ") + ";");
});
})();
echo-play.js
This snippet will write out all get and play commands being sent to Photoshop, and their responses
(function () {
var Descriptor = __PS_ADAPTER__.ps.descriptor,
log = __LOG_UTIL__;
log.enableAll();
var originalPlay = Descriptor.play;
var originalBatchPlay = Descriptor.batchPlay;
var originalGet = Descriptor.get;
Descriptor.play = function (name, descriptor, options) {
var str = "('" + name + "', " + JSON.stringify(descriptor, null, " ") + ", " +
JSON.stringify(options, null, " ") + ");";
log.debug("play: " + str);
return originalPlay.call(Descriptor, name, descriptor, options).then(function (result) {
log.debug("play result: " + JSON.stringify(result, null, " "));
return result;
});
};
Descriptor.batchPlay = function (commands, options, batchOptions) {
var str = "(" + JSON.stringify(commands, null, " ") + ", " +
JSON.stringify(options, null, " ") + ", " +
JSON.stringify(batchOptions, null, " ") + ");";
log.debug("batchPlay: " + str);
return originalBatchPlay.call(Descriptor, commands, options, batchOptions).then(function (result) {
log.debug("batchPlay result: " + JSON.stringify(result, null, " "));
return result;
});
};
Descriptor.get = function (reference) {
log.debug("get: " + JSON.stringify(reference, null, ""));
return originalGet.call(Descriptor, reference).then(function (result) {
log.debug("get result: " + JSON.stringify(result, null, " "));
return result;
});
};
}());
ps-events.js
Yet another snippet to echo notifications in Design Space (from this page).
var psNotifierHandler = function(err, type, info) {console.log("ps-notification:'" + type + "' info:" + JSON.stringify(info));};
_spaces.setNotifier(_spaces.notifierGroup.PHOTOSHOP, {}, psNotifierHandler);
classic-ui-and-menu.js
The following snippet will turn on classic Photoshop overlay, without switching to classic Photoshop (will break UI and certain functionality!)
window._spacesToggled = (window._spacesToggled === undefined) ? true : window._spacesToggled;
(function () {
var ui = __PS_ADAPTER__.ps.ui;
var flux = __FLUX_CONTROLLER__.flux;
if (window._spacesToggled) {
ui.setClassicChromeVisibility(true);
ui.installMenu({}, {});
} else {
ui.setClassicChromeVisibility(false);
flux.actions.menu.beforeStartup();
}
window._spacesToggled = !window._spacesToggled;
}());
current-layer.js
This snippet will print out the currently selected layer's descriptor
var d = __PS_ADAPTER__.ps.descriptor;
d.get("layer").then(function (result) { return JSON.stringify(result, null, " "); }).then(console.log.bind(console));
load-flux.js
This snippet will load Flux to a variable for use in console
flux = __FLUX_CONTROLLER__.flux;
echo-transform.js
This snippet will print out request/response of all transform commands
/**
* This snippet will print any of the transform commands we're sending Photoshop
* and their results
**/
(function () {
var Descriptor = __PS_ADAPTER__.ps.descriptor;
log = __LOG_UTIL__;
log.enableAll();
var originalBatchPlay = Descriptor.batchPlay;
Descriptor.batchPlay = function (commands, options, batchOptions) {
commands.forEach(function (command) {
if (command.name === "transform") {
log.debug("Transform command being sent:");
log.debug(JSON.stringify(command, null, " "));
}
});
return originalBatchPlay.call(Descriptor, commands, options, batchOptions).then(function (result) {
result.forEach(function (res) {
if (res.hasOwnProperty("freeTransformCenterState")) {
log.debug("Transform result from Photoshop:");
log.debug(JSON.stringify(res, null, " "));
};
});
return result;
}).catch(function (err) {
log.debug(err);
log.debug(JSON.stringify(commands, null, " "));
});
};
}());