gyro永不抽风！ - Adobe
type: channel
link: https://gallery.gyrojeff.top/index.php/tag/Adobe/
items: Photoshop CEP 开发 - 和外部程序通信的探索

Photoshop CEP 开发 - 和外部程序通信的探索
type: item
date: 2021-10-04T03:55:19+00:00
description: As most people use Photoshop as image editing software, I designed a two-way interaction method between Photoshop and the main application in order to achieve the goal of exporting the document to Photoshop automatically, which can enable further customized editing. The design has two components: a Photoshop CEP extension and the main application. The following diagram shows how the system works: As CEP framework is based on Chromium, and Adobe provided a csInterface which can enable us to evaluate ExtendScript expressions, I proposed the framework above, with the main idea of using HTTP server to communicate with the main application. 关于 HTTP Server 根据 https://wttech.blog/blog/2020/creating-custom-extension-for-adobe-photoshop/ , 初始化node，安装相关库： Working with Node.js in CEF client is really simple and straightforward and only requires 2 lines of configuration. In your manifest.xml under just paste this lines: --enable-nodejs --mixed-context --enable-nodejs - it enables Node.js in the Chromium. Thanks to that you can use all of Node.js API without any custom configuration. This configuration can be summarized with a famous cite by Todd Howard from Bethesda Games Studio - It just works! --mixed-context - it enables working with mixed content in the Chromium so you will not get any unexpected errors It should look like this: ... ./index.html --enable-nodejs --mixed-context ... 安装相关库 npm install express 接下来该怎么写怎么写，详见：https://github.com/JeffersonQin/YuzuMarker.Photoshop 关于 JS 调用 ExtendScript 我写了一个正则匹配来转义参数： function repr(val) { return val.replace(/\\/g, '\\\\').replace(/\'/g, '\\\'').replace(/\"/g, '\\\"').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r').replace(/\&/g, '\\\&'); } 使用样例： 首先初始化 CSInterface: var csInterface = new CSInterface(); 在 ExtendScript 中写好相关逻辑 (无关紧要) cTID = function(s) { return app.charIDToTypeID(s); }; sTID = function(s) { return app.stringIDToTypeID(s); }; function applyMask() { function step1(enabled, withDialog) { if (enabled != un…