rkamysz / adobe-node

Control Adobe applications - such as Photoshop, Animate, Illustrator, InDesign - from node. Run JavaScript to remotely - from the command line - create, modify or export document content. This module can be used to automate the workflow by creating an action chain that can be executed without user intervention.
MIT License
63 stars 10 forks source link

Additional informations #1

Closed Roms1383 closed 4 years ago

Roms1383 commented 4 years ago

Hi @rkamysz, I found your library and it looks really amazing !

I personally wrote an automation script a couple of days ago for Illustrator (basically opening each file of a folder, tracing the image to vector, resizing artboard and exporting it as a SVG) and thought I could make good use of your library to automate it a little bit more (which is to say : open Illustrator automatically, remove already exported images after each batch and maybe some more).

I tried it first using a refactored version of my custom script, but there's something that I didn't understand.

As a fallback I tried the example shown in the README, simplified to only open and close Adobe Photoshop, but it only gives this output :

Adobe Event Listener running at localhost:5000

There's clearly something running but my Photoshop never get opened, it's just stuck indefinitely.

I double checked the software paths, potential JS issues and everything looks correct. Is there the need for another Adobe technology to run it as a server or something ?

Thanks :)

rkamysz commented 4 years ago

Hi @Roms1383, Thank you very much, I will try to help, but I need to know what system you are using and which version of the Adobe application. You can check if there are scripts in the directory you set for adobeScriptsPath.

app.open (); and app.close (); are based on node.js processes The following piece of code is responsible for opening the application: https://github.com/rkamysz/adobe-node/blob/master/src/process.ts#L27

Each other script is created on the basis of templates and saved in the one indicated above. I currently don't have access to Adobe applications and this can be a bit problematic, but I will try to help.

Also try to close all Adobe apps before you run the script.

Roms1383 commented 4 years ago

Thanks @rkamysz šŸ˜ƒ

environment

MacOS Catalina version 10.15.2 (19C57)

Adobe Illustrator CC 2019 23.0.4 trial version

files

My files are located in a project in some folder on my computer, not directly inside adobeScriptPath if that matters. Here is the sample :

src/automation/photoshop.ts

import { newAdobeApp, AdobeAppName, AdobeAppEvent, AdobeApp, BroadcastMessage } from "adobe-node";

const sleep = (duration: number) => new Promise(resolve => { setTimeout(resolve, duration) });

const main = async () => {
    const app: AdobeApp = newAdobeApp({
        app: {
            name: AdobeAppName.Photoshop,
            path: '/Applications/Adobe Photoshop CC 2019/Adobe Photoshop CC 2019.app/Contents/MacOS/Adobe Photoshop CC 2019',
            adobeScriptsPath: '/Applications/Adobe Photoshop CC 2019/Presets/Scripts'
        },
        host: 'localhost',
        port: 5000
    });

    app
    .on(AdobeAppEvent.OpenApp, () => {
        console.log(`The Adobe App is open`);
    })
    .on(AdobeAppEvent.NewDocument, () => {
        console.log(`The document has been created`);
    })
    .on(AdobeAppEvent.OpenDocument, (data: any) => {
        console.log(`The document has been opened`);
    })
    .on(AdobeAppEvent.CloseDocument, () => {
        console.log(`The document has been closed`);
    })
    .on(AdobeAppEvent.CloseApp, () => {
        console.log(`The Adobe App has been closed`);
    })
    .on("test_script", (message: BroadcastMessage) => {
        console.log(`Testing custom script - ${message}`);
    });

    app.init();

    await app.open();
    await sleep(2000);
    await app.close();
    app.dispose();
}

main();

package.json (simplified)

{
  "scripts": {
    "lint:ts": "yarn tslint -e 'node_modules/**' -e 'dist/**' -c tslint.json --fix '**/*.ts'",
    "lint:md": "yarn remark .",
    "lint": "yarn lint:ts && yarn lint:md",
    "build": "rm -rf dist && tsc -p tsconfig.json",
    "presample": "yarn build",
    "sample": "node dist/automation/photoshop"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "target": "es6",
    "module": "commonjs",
    "lib": ["dom","es2015","es2016","es2017","es2018"],
    "types" : ["node", "@types/jest"],
    "noImplicitAny": false,
    "resolveJsonModule": true,
    "preserveConstEnums": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true
  },
  "exclude": [
    "**/*.spec.ts",
    "**/*.test.ts",
    "src/seeds/**",
    "**/*.stories.[tj]s",
    "node_modules",
    "dist"
  ]
}

execution

All Adobe applications were closed when I was running the script with :

āžœ  automation git:(master) āœ— yarn sample           
yarn run v1.21.1
$ yarn build
$ rm -rf dist && tsc -p tsconfig.json
$ node dist/automation/photoshop
Adobe Event Listener running at localhost:5000
Roms1383 commented 4 years ago

Also, I tried running manually :

āžœ  automation git:(master) āœ— open -a "/Applications/Adobe Photoshop CC 2019/Adobe Photoshop CC 2019.app/Contents/MacOS/Adobe Photoshop CC 2019"

and it opened Photoshop correctly

rkamysz commented 4 years ago

Hi @Roms1383, I'll check it out this weekend.

rkamysz commented 4 years ago

Strange thing is that it works when I link this package and there is something wrong with mkdirp in script-file-creator.ts this is the place where it hangs.

rkamysz commented 4 years ago

please try version @1.1.2

Roms1383 commented 4 years ago

Ok so I updated the library then got on first run :

āžœ  refacto git:(master) āœ— yarn sample                                                        
yarn run v1.21.1
$ yarn build
$ rm -rf dist && tsc -p tsconfig.json
$ node dist/automation/photoshop
Adobe Event Listener running at localhost:5000
(node:4219) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, open '/Applications/Adobe Photoshop CC 2019/Presets/Scripts/open_app.jsx'
(node:4219) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4219) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Please note there seems to be an uncatched Promise rejection here, although I haven't checked the code.

So I ran the following command :

āžœ  refacto git:(master) āœ— sudo chown romain "/Applications/Adobe Photoshop CC 2019/Presets/Scripts/"

Please note that one would have to replace romain with his/her own username, and I think that's something you should mention in the README @rkamysz.

Also you're right about the comment concerning PSUserConfig.txt file for Photoshop, I was requested it on launch.

I'm a bit concerned that it has some security implications, but not much given it's only Adobe softwares allowed access, and it can reverted in case of doubt.

Thanks for your help !