• CEP

HTML Panel Tips #18: Photoshop JSON Callback

CC 2015 previews a new Photoshop Event listening system and deprecates the "com.adobe.PhotoshopCallback", due to a bug that makes all the extension receiving the event - that is: if two panels are registered for the event “make”, then each panel sees the other panel’s “make” event, and must ignore it. The solution implemented marks a break in retro-compatibility and is going to be the only one accepted from Photoshop CC2016 (version 17.x) onwards. Let’s have a look at what is that all about.

Please refer to HTML Panels Tips: #7 Photoshop Events, Take 1 to review how PS events listening works. Now, there are three different changes you must be aware of:

  1. "com.adobe.PhotoshopJSONCallback" is the replacement event - no more "com.adobe.PhotoshopCallback".
  2. The ExtensionID must be appended as a suffix.

So what used to be:

var csInterface = new CSInterface();
csInterface.addEventListener("PhotoshopCallback", PSCallback);

now becomes:

var csInterface = new CSInterface();
var extensionId =  csInterface.getExtensionID();
csInterface.addEventListener("com.adobe.PhotoshopJSONCallback" + extensionId, PhotoshopCallbackUnique);
  1. The data property of the CSEvent that the PhotoshopCallbackUnique receives is a JSON string hidden inside a string.
function PhotoshopCallbackUnique(csEvent) {
  console.log(csEvent);
}
// ver1, {
//   "eventID": 1298866208,
//   "eventData": {
//     "documentID": 1566,
//     "new": {
//       "_obj": "document",
//       "depth": 8,
//       "fill": {
//         {
//           "_enum": "fill",
//           "_value": "white"
//         },
//         "height": {
//           "_unit": "distanceUnit",
//           "_value": 360
//         },
//         "mode": {
//           "_class": "RGBColorMode"
//         },
//         "pixelScaleFactor": 1,
//         "profile": "sRGB IEC61966-2.1",
//         "resolution": {
//           "_unit": "densityUnit",
//           "_value": 300
//         },
//         "width": {
//           "_unit": "distanceUnit",
//           "_value": 504
//         }
//       }
//     }
//   }

As you see, there’s a ver1, that needs to be stripped. Also, as a bonus, extra information is provided as JSON (here a New Document’s been created). I’ve uploaded a demo extension on my GitHub repo, which looks like:

Which basically let you switch on/off listeners to the corresponding events ("make", "duplicate", etc are the stringID). You can find the full code on GitHub, yet the relevant files are:

HTML

I’ve used Topcoat CSS (apparently not anymore maintained, but I love them), nothing too fancy.