Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Events, open document, and in-script event handlers

Participant ,
Feb 07, 2018 Feb 07, 2018

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.

TOPICS
Actions and scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 08, 2018 Feb 08, 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'))

Translate
Adobe
Community Expert ,
Feb 07, 2018 Feb 07, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2018 Feb 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2018 Feb 08, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2018 Feb 08, 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'))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2018 Feb 08, 2018
LATEST

that was it. thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines