Skip to main content
bluebeezle
Inspiring
February 8, 2018
Answered

Events, open document, and in-script event handlers

  • February 8, 2018
  • 2 replies
  • 1676 views

Hey guys, I'm new to scripting in Photoshop and could use some help using events.

I need a script to open some files and copy some layers between them. Unfortunately, when using file.execute to open them (file.open doesn't seem to work, despite returning true), the documents aren't ready by the time my script references them.

So I have to wait for an open document event to fire.

Is there a way to set up an event listener that will call a function in the same script? I need access to variables in my main script, so calling an external script as an event handler isn't super useful anyways.

That being said, I went ahead and tried app.notifiers.add("Opn ", new File(scriptPath + "ExternalEventHandlerScript.jsx")); anyways, and that was misbehaving as well - it won't work the first time I run the script - the errors out with "Notifier already installed". But if I then remove the code and run the script from my panel again, the external event handler will run properly.

TLDR: Is there a way to set up an event listener that will call a function in the same script? I need access to variables in my main script, so calling an external script as an event handler isn't super useful anyways.

This topic has been closed for replies.
Correct answer Kukurykus

Execution does not wait referenced file finish its commands (as it's not meant to open graphic files, but more to execute scripts), so the program that triggered it reads next its lines in no time. Correct use of opening graphic file is for example:

open(File('~/desktop/someFile.psd'))

2 replies

Kukurykus
KukurykusCorrect answer
Legend
February 8, 2018

Execution does not wait referenced file finish its commands (as it's not meant to open graphic files, but more to execute scripts), so the program that triggered it reads next its lines in no time. Correct use of opening graphic file is for example:

open(File('~/desktop/someFile.psd'))

bluebeezle
Inspiring
February 8, 2018

that was it. thanks.

JJMack
Community Expert
Community Expert
February 8, 2018

I'm a bit confused. What kind of event handler are you trying to open a document in and why are you trying to through that over the wall using file.execute is the file associated with Photoshop even? How would your script relinquish control terminate andthen  get control when Photoshop opens the file should the file be associated with Photoshop.

JJMack
bluebeezle
Inspiring
February 8, 2018

The files are PSD files. I'm only using file.execute because I couldn't get file.open to work. Basically, I have script that I need to run, copying layers between two PSD files, after the script finishes opening both files.

JJMack
Community Expert
Community Expert
February 8, 2018

What kind of event handler are you trying to start the ball rolling with.  How would the handler know which two PSD file to open and after the two documents are open why would the handler not simply execute the script code you want to use on the two  document it opened it knows which two document it opened.

I think  you should post your two script the even handler script  and the layers copying script.

JJMack