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

Help with a script to automate a task!

Engaged ,
Mar 10, 2017 Mar 10, 2017

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();

TOPICS
Actions and scripting

Views

736

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

correct answers 1 Correct answer

Contributor , Mar 11, 2017 Mar 11, 2017

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

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Mar 10, 2017 Mar 10, 2017

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.

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
Engaged ,
Mar 11, 2017 Mar 11, 2017

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.

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
Contributor ,
Mar 11, 2017 Mar 11, 2017

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!') 

  }; 

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
Engaged ,
Mar 12, 2017 Mar 12, 2017

Copy link to clipboard

Copied

LATEST

That's right, perfect!

Now I can understand how this process is done greenrookie. Thanks for the help brother!

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