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

JS CS4 & CS5 working through the ScriptListener

Explorer ,
Jun 22, 2010 Jun 22, 2010

Copy link to clipboard

Copied

Working through the guide there is an example:

var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx")
app.notifiers.add( "Opn ", eventFile)

There is 2 possible places to save this file in windows:

C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts

or


C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts\Event Scripts Only

I've tried both and when I open a file in Photoshop I do not get the alert.

If I go into the Script Event Manager and set the above code to run on Open Document event it works.

Is there a way to get this example to work without setting it up in the Script Event Mananger?

Cheers.

TOPICS
Actions and scripting

Views

1.8K

Translate

Translate

Report

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
Adobe
Advisor ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Open ESTK

Open a new file

Copy your code to the file

Set the debug target to PS

Run the code with the debugger's Play button

Or save the code to a JSX file and run it  via File > Scripts > Browse or from within ESTK as described above.

-X

Votes

Translate

Translate

Report

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
Adobe Employee ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Odd, running the script from ESTK does not work but appears to do the right thing. Running it via drag/drop and it works correctly. You need to add the following line to your script.

app.notifiersEnabled = true;

Votes

Translate

Translate

Report

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
Explorer ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Thanks Tom it sort of works,

If I run the line app.notifiersEnabled = true; in the ESTK then it works fine. I set it back to false and add the code to the script, restart PS and still nothing.  I've tried placing the script in just the scripts folder and in just the Event Scripts Only but with no luck.

Is there a way to run the app.notifiersEnabled = true; without having to run it in ESTK?

app.notifiersEnabled = true;
var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");
app.notifiers.add( "Opn ", eventFile);

Votes

Translate

Translate

Report

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
Advisor ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

IIRC, if you use the API to register a notification, it only lasts the duration of that PS session. You have to run it each time you run PS or you need to use the Scripts Event Manager.

It doesn't matter where the file is located as long as it matches the path that you specify.

Votes

Translate

Translate

Report

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
Explorer ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Thanks xbvtor2,

I did notice that app.notifiersEnabled = true; turns on the Script Event Manager. So if I was to place that code in the scripts folder should it not automatically enable the Script Event Manager every time I start PS?

I'm losted as to why even through I've put the app.notifiersEnabled = true; line in the code the SEM does not get enabled. The path is correct because when SEM is enabled the alert works every time. I also noticed that even though I ran the line in the ESTK if I restarted PS it was still enabled.

Cheers, John.

Votes

Translate

Translate

Report

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
Guru ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

My experence is that you only need to set app.notifiers.enabled to true if it is not already set. It can be set to true by a script or the Scripts Events Manager.

If you register an event using app.notifiers.add in ESTK the event does not run the script unless Photoshop is restarted. If it is added as part of a script run in Photoshop or the Script Events Manager it runs without restart.

As X pointed out the scirpt can be anywhere, it doesn't have to be in one of those two locations. But for me events registered with the API remain registered from session to session untill removed.

Here is a save way to register an event. Note that it only sets app.notifiers.enabled to true if it is false and registers the open event only if there is not already one.

if(!app.notifiers.enabled) app.notifiers.enabled =  true;
var hasOpenEvent = false;
for(var e = 0;e<app.notifiers.length;e++){// the only way to tell which events are in use is to loop notifiers
     if(app.notifiers[0].event == 'Opn ') hasOpenEvent = true;
}
if(!hasOpenEvent) {
     var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");
     app.notifiers.add( "Opn ", eventFile);
}

And as I understand it

new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");

will only work with English versions of Photoshop.

Votes

Translate

Translate

Report

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
Advisor ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

But for me events registered with the API remain registered from session to session untill removed.

I may have been doing something wrong when I originally tried this. It wasn't what I needed anyway since I only wanted the notification registered for the session and wrote a bunch of code to auto-register/deregister the script.

And as I understand it

new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");

will only work with English versions of Photoshop.

I checked serveral European and Asian language installs that I've got and none of the paths below Presets are localized. The Samples and Scripting Documentation folders are, however.

Votes

Translate

Translate

Report

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
Guru ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

LATEST

xbytor2 wrote:

I checked serveral European and Asian language installs that I've got and none of the paths below Presets are localized. The Samples and Scripting Documentation folders are, however.

That is good to know. In my notes I have several ZStrings for folders. I guess becuse I found ZStrings I thought they were localized.

"$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"
"$$$/private/Plugins/DefaultPluginFolder=Plug-Ins"
"$$$/ApplicationPresetsFolder/Presets=Presets"
"$$$/private/FolderName/UserPresetsFolder/Presets=Presets"

Votes

Translate

Translate

Report

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
Explorer ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

Thanks Michael,

I must be missing somthing. I tried your code was was not able to get it to work. I thought I'd take it one step back and tried:

if(!app.notifiers.enabled) {
    alert("true");
    app.notifiers.enabled =  true;
    }else{
        alert("false");

Placed this in the scritps folder got nothing. Ran it from the ESTK and keeped getting true.

So I change app.notifiers.enabled to app.notifiersEnabled and still got nothing when PS starts but if I run it in the ESTK i'll get true then false etc.

if(!app.notifiersEnabled) {
    alert("true");
    app.notifiersEnabled =  true;
    }else{
        alert("false")

Votes

Translate

Translate

Report

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
Explorer ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

After a bit of searching on the web I found C:\Program Files\Common Files\Adobe\Startup Scripts CS5\Adobe Photoshop.

I place the following code in there:

if(!app.notifiersEnabled) {
    app.notifiersEnabled =  true;
    }

This seems to work but as the info I found stated every time you run a script this code is executed. So if I try and disable ESM it automatically comes back enabled.  I could be wrong but I gather that scripts in the C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts do not automatically execute and this might be due to security issues. I have found that I have to select them via the File/Scripts menu in PS.  If anyone is aware if this is the case I'd be grateful for the confirmation.

Votes

Translate

Translate

Report

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
Advisor ,
Jun 23, 2010 Jun 23, 2010

Copy link to clipboard

Copied

I could be wrong but I gather that scripts in the C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts do not automatically execute

That is true. File > Scripts is how those are executed. If you want a script to run everytime PS launches, look for:

   On WinXP CS2
      %CommonProgramFiles%\Adobe\StartupScripts
   On WinXP CS3
      %CommonProgramFiles%\Adobe\Startup Scripts CS3\Adobe Photoshop
   On WinXP+ CS4
      %CommonProgramFiles%\Adobe\Startup Scripts CS4\Adobe Photoshop
   On WinXP+ CS5
      %CommonProgramFiles%\Adobe\Startup Scripts CS5\Adobe Photoshop

%CommonProgramFiles% is usually equivalent to something like:
    C:\Program Files\Common Files\

Votes

Translate

Translate

Report

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