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

I need js global vars in PS-64bit CS6, but they aren't staying in memory.

Explorer ,
Aug 23, 2013 Aug 23, 2013

I have read that global vars in Photoshop are only kept in memory if they are defined in a startup script, but I have found that the App Start event 'Ntfy' doesn't seem to qualify as a startup script in that sense. Through experimentation on my PC, I have found that a global variable defined in a script that is set in the Script Events Manager UI to run at App Start doesn't stay in memory. (Sorry that sentence is so long).

The other method of startup scripts, putting a script in C:\Program Files\Common Files\Adobe\Startup Scripts CS6\Adobe Photoshop, doesn't work for me.  The directory didn't exist, so I made it and put a simple script(var declarations and an alert() command) in it.  The simple script never ran because the alert window never popped up and the variables were never defined.

Since the document close event doesn't provide the name of the document that was closed, I need global vars to keep track of the open documents before and after the event.  I could use a file to save that data, but that is not the best solution.

Thanks for your help.

TOPICS
Actions and scripting
854
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

Guru , Aug 23, 2013 Aug 23, 2013

Even though you are running the 64bit version of Photoshop the startup files are in the Program Files (x86) tree. Do a search in Windows Explorer for photoshop.jsx to find the exact folder path.

However instead of using global variables I would suggest you store the data you need in customOptions.

Translate
Adobe
Guru ,
Aug 23, 2013 Aug 23, 2013

Even though you are running the 64bit version of Photoshop the startup files are in the Program Files (x86) tree. Do a search in Windows Explorer for photoshop.jsx to find the exact folder path.

However instead of using global variables I would suggest you store the data you need in customOptions.

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
Explorer ,
Aug 23, 2013 Aug 23, 2013

That made my script run! But it seems to run more than just at App Start. My startup script seems to run at startup, when I access a global var, and whenever one of my scripted events occurs or I open the Script Events Manager.  Is that normal?  I'm going to try customOptions instead.

Thanks for help!

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
Guru ,
Aug 23, 2013 Aug 23, 2013

Yes that is normal. Most of the time all you want in the startup script is to define properties and methods. The script does not do anything other than maybe some needed setup.

For example if you wanted a startup script to keep track of open documents your script may look something like this.

var milesScriptObject = {};

milesScriptObject.openDocuments = [];

milesScriptObject.docCount = function(){ return this.openDocuments.length; };

milesScriptObject.add = function( doc ){ this.openDocuments.push(doc);};

milesScriptObject.remove = function( doc ){

    for(var arrayIndex=0;arrayIndex< this.openDocuments.length;arrayIndex++){

        if(this.openDocuments[arrayIndex]===doc) this.openDocuments.splice(arrayIndex,1);

    }

};

Then in another script you access those methods and properties.

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
Explorer ,
Aug 26, 2013 Aug 26, 2013
LATEST

Cool recipe.  I had to look up what {} meant, but now I have a whole new way to attack javascript problems. Thanks for your help.

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