Copy link to clipboard
Copied
Hello, everyone!
I have a script here and need to modify it to work as follows:
1- (Process 1) Open a document to start a task.
2- (Process 2) If the document is already open, I do not need to open it again to repeat the task!
I just need to skip the (Process 1) if the document is already open!
Maybe this seems a very silly thing, but fundamental to my tasks. Thank you!
Here is my script:
#target photoshop
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function Open() {
// Process 1
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putInteger(cTID('DocI'), 4205);
executeAction(cTID('Opn '), desc1, dialogMode);
};
// Process 2
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
alert('Here starts the Task!')
};
step1(true, true); // Open
step2();// Start
};
Open.main = function () {
Open();
};
Open.main();
Like this?
...#target photoshop
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
if (app.documents.length > 0) {
step2();
}
else {step1();
step2();}
// Process 1
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putInteger(cTID('DocI'), 4205);
ex
Copy link to clipboard
Copied
You can check all opened documents.
var documents = app.documents;
for(var i = 0;i<documents.length;i++){
try{
alert(documents.fullName);
}
catch (e){
alert(e);
}
}
And do something if document paths are same.
Copy link to clipboard
Copied
Hi Jarda Bereza Thanks for the attention! I understood here how to run your script. Not quite what I need. Maybe you did not understand the question.
It would have to be something like this:
If the document has already been opened: Run the script from "Process 2" (Line 19)
Else the document was not open: Run the script from "Process 1" (Line 08)
I think it's better to understand!
Thank you.
Copy link to clipboard
Copied
Like this?
#target photoshop
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
if (app.documents.length > 0) {
step2();
}
else {step1();
step2();}
// Process 1
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putInteger(cTID('DocI'), 4205);
executeAction(cTID('Opn '), desc1, dialogMode);
};
// Process 2
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
alert('Here starts the Task!')
};
Copy link to clipboard
Copied
That's right, perfect!
Now I can understand how this process is done greenrookie. Thanks for the help brother!