Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now