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
64 stars 10 forks source link

AdobeApp.runScript never resolves #2

Open coeing opened 4 years ago

coeing commented 4 years ago

Hey @rkamysz ,

First of all: Thanks for starting this nice library :) It's quite a niche thing, but exactly what we needed for our automatisation process which involves some Adobe products (Photoshop & Illustrator).

Unfortunately I'm currently stuck with a little problem: The promise which is returned from triggering the custom scripts never resolve, so the application hangs. The logic inside the script is executed, but it feels like the callback gets lost somewhere. Is there a way to check if the adobe-broadcast was called and the callback data was received correctly?

Strangely it worked on my local machine where I used Photoshop CS6. Our main server runs Photoshop CC 2019 and Illustrator CC 2019. It also didn't work with Illustrator CC 2020 on my local machine. So it looks like it has to do with the used version?

When I'm back in office (probably next Wednesday), I can give it a try with Photoshop CC 2019 on my local machine.

rkamysz commented 4 years ago

Hi @coeing , I'll check it out this weekend. I don't have an adobe application so it can be a little difficult. I'll check if I can download the trial version or ask friends to try at home.

Currently I'm working on new ChegoJS

coeing commented 4 years ago

Hey @rkamysz ,

Thanks a lot for your quick answer :)

I already read in the Readme that you don't have the Adobe applications at hand. Seems a bit hard to reproduce the incoming issues ;)

If you have no luck finding the issue I'll see if I can find a solution and create a pull request. I already dived into the details of your package, it seems quite clear to me what should happen between the node application, the "adobe-broadcast" server and the adobe application.

rkamysz commented 4 years ago

Hi @coeing, cool I will also try

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

coeing commented 4 years ago

Thanks for looking into the issue! :) I will try it on Wednesday when I work on the project again.

Just a guess due to the different behaviour between linking the package and using a dependency: Is it possible that the adobe-broadcast binary could not be found?

rkamysz commented 4 years ago

Hi @coeing, no problem, I hope this works. To answer your question, this package contains one bin adobe-broadcast and if you call npm link, it should create an alias in the bin folder in your current node. To quote the classic: "works on my machine", I tested before releasing the latest version. You can also use npm pack.

Good luck

rkamysz commented 4 years ago

@1.1.3

coeing commented 4 years ago

Hi @rkamysz ,

Unfortunately the new version didn't make a change in the behaviour, the promises still never resolve :/ Any suggestion how I can debug it?

Cheers Christian

rkamysz commented 4 years ago

Hi, I will have a closer look, could you provide me this script?

coeing commented 4 years ago

Even the Promise which is returned by AdobeApp.open() doesn't resolve, so it feels like a general problem.

But here's a small script which opens a file:

(function(filePath) {
  app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
  app.open(File(filePath));
  return true;
})(filePath);
rkamysz commented 4 years ago

I will check that

rkamysz commented 4 years ago

Hey I see the problem I will solve it after work

rkamysz commented 4 years ago

Hi I think that current resolving promises is naive but you can try with latest changes on branch issues-2, link it to your project. Please setup event listeners for your custom script, as an event set script name eg. if script path is /some/foo.js then event would be foo

rkamysz commented 4 years ago

Btw about closing the application, if you start photoshop with this 'home/welcome/what's new' screen adobe-node will close this window not editor. To solve that disable home screen link

coeing commented 4 years ago

Thanks for checking out the issue. Were you able to reproduce it?

About the promises: I still think that it hasn't to do with the promises themselves, but with the callback from the adobe application never arriving. As I wrote it worked with Photoshop CS6 for me, but the new version (tested CC19 + CC20) don't work anymore.

rkamysz commented 4 years ago

Hi, I don't want to write it "works on my machine" but it does with CC2020 (trial) - 2 days left. Did you try on branch issues-2?

...
app.on('custom_script', (message) => {
    console.log(`Testing custom script DONE - ${message}`);
});
await app.init();
await app.open();
await app.newDocument();
await app.runScript('custom_script.js');
await sleep(4000);
await app.close();
app.dispose();
...

./js/custom_script.js

(function(){
    return true;
}());

Do you keep your js files in js folder?

output:

Adobe Event Listener running at localhost:5000
The Adobe App is open
Built-in Script file found: /Users/radoslawkamysz/git/adobe-node/scripts/photoshop/new_document.js
The document has been created
Custom script file found: js/custom_script.js
Testing custom script DONE - true
The Adobe App has been closed
Adobe Event Listener has been stopped at port 5000
rkamysz commented 4 years ago

When I run your script

(function(filePath) {
  app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
  app.open(File(filePath));
  return true;
})(filePath);

Im getting this

...
Testing custom script DONE - undefined
...

but that is ok cuz filePath is undefined

coeing commented 4 years ago

Okay, thanks for creating the test case. I will check it out with it on my machine next week (probably on Wednesday again), too.

rkamysz commented 4 years ago

Ok, but did you use issue-2 branch, before?

coeing commented 4 years ago

Just working on it today, so sorry for the late response.

What I found out is that the app.system function that you use to trigger the adobe-broadcast doesn't exist in Illustrator at all: https://community.adobe.com/t5/illustrator/is-it-possible-to-copy-text-to-the-clipboard-in-illustrator-via-javascript/m-p/3424663#M154037 It is just a thing in Photoshop and Bridge. So we will need another method to send data back to the Node application. I am currently trying to find out what options we have.

coeing commented 4 years ago

Okay, I have at least found a way to make it work with Adobe Bridge, but I really hope there is a better one: https://stackoverflow.com/a/21444343/1346183

The usage of BridgeTalk is also used by this developer: http://selfdocumentingcode.blogspot.com/2009/05/cross-scripting-adobe-illustrator-and.html

Will try it by adjusting your package locally, I can add a pull request if it works :)

coeing commented 4 years ago

Got it to work finally, but I will need some time to clean it up and test it a bit before I create a Pull Request. Probably doing it on Wednesday next week.

rkamysz commented 4 years ago

Hi @coeing that is great news! Sorry I had no time recently. Thanks man

coeing commented 4 years ago

Added a pull request #5 . Feel free to edit it as you think before merging it. If you have questions about the changes, let me know :)

rkamysz commented 4 years ago

Hi @coeing, thank you for your effort, as soon as will have some time I will check that and release new version.

pdkn commented 4 years ago

This is great. Any chance you can merge issues-2 branch into master so it's accessible via npm i adobe-node ? At moment the master branch app.runScript() doesn't work

rkamysz commented 4 years ago

Hi I want to change one small thing in the PR and then I merge. 100% I will do it this week

pdkn commented 4 years ago

Smashing, since swapping over to issues-2 branch the event broadcasting is failing. I can see mention of running npm link. which I've run from root of my project but no joy. Any pointers?

rkamysz commented 4 years ago

Hi @pdkn and @coeing sorry for this delay but recently I have no time for my private projects + no Adobe App Licenses :) Ive added BridgeTalk but I cant test it please check it on bridge-talk branch. Clone it then run tsc && npm pack then install it in your node app via npm i ...path_to/adobe-node-1.1.4.tgz