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

conditional script by a specific part in the docname

Explorer ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

I've made something to have this  kind of stricture on picture i work :

0000000000001_v1_fg1208015_det.jpg

I would like to know if i can script anything from part of the name, for example a got a part named v1 is ( View 1),

but i got also, at the same place in the structure v2 or v3 etc...

My idea is to make a  script condition from this only part of the document name.

Thx for helping

TOPICS
Actions and scripting

Views

457

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

Explorer , Aug 12, 2016 Aug 12, 2016

If you want to do this one document at a time (or automate > batch it on a whole folder later) use this:

var workingName = app.activeDocument.name;

if(workingName.match(/(v1)/ig)){

    //do something

    } else if (workingName.match(/(v2)/ig)){

    //do something

    } else if (workingName.match(/(v3)/ig)){

    //do something

}

If you want to loop through all open documents use this:

for (i = 0; i < documents.length; i++){

    var curDoc = app.activeDocument = app.documents;

    var workingName = curDoc.nam

...

Votes

Translate

Translate
Adobe
Explorer ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

If you want to do this one document at a time (or automate > batch it on a whole folder later) use this:

var workingName = app.activeDocument.name;

if(workingName.match(/(v1)/ig)){

    //do something

    } else if (workingName.match(/(v2)/ig)){

    //do something

    } else if (workingName.match(/(v3)/ig)){

    //do something

}

If you want to loop through all open documents use this:

for (i = 0; i < documents.length; i++){

    var curDoc = app.activeDocument = app.documents;

    var workingName = curDoc.name;

    if(workingName.match(/(v1)/ig)){

        //do something

        } else if (workingName.match(/(v2)/ig)){

        //do something

        } else if (workingName.match(/(v3)/ig)){

        //do something

        }

    }

NOTE: the 'i' toward the end of each regex pattern makes this case insensitive....if you want it to be case sensitive get rid of the 'i'. Also, in the second option if the "do something" part includes closing the document, this will throw off the loop. In that case change the iteration to count backwards like this:

for (i = app.documents.length - 1; i >= 0; i--)

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
Community Expert ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

Hi squirpy​,

not bad. But you work with maximum risk.

Looking for (only) /(v1)/ can produce false positive hits.

e.g.

if the filename is not: 0000000000001_v1_fg1208015_det.jpg

rather is: 0000000000001_v1_fv1208015_det.jpg

A bit more safety give you the search with /_v1_/

(and much more safety with /\d{13}_v1_/ ) But nobody (except showshow) knows which possibilities in the kind of structure really exists.

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 ,
Aug 12, 2016 Aug 12, 2016

Copy link to clipboard

Copied

Good call. As you mentioned, we don't know the specifics regarding anything that could produce false positives, but including the underscores is a no-brainer.

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 ,
Aug 16, 2016 Aug 16, 2016

Copy link to clipboard

Copied

So if i well understand it is not absoluty safe method ...?

Thx any way

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 ,
Aug 16, 2016 Aug 16, 2016

Copy link to clipboard

Copied

even if my structure is still like this

x=number

xxxxxxxxxxxxx_vx(1,2,3,4,5 max)_fgxxxxxxx_det.jpeg

??

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
Community Expert ,
Aug 16, 2016 Aug 16, 2016

Copy link to clipboard

Copied

LATEST

A little bit more flexibility and secure:

// name_checkPartOfDocName.jsx

// https://forums.adobe.com/thread/2194599

// conditional script by a specific part in the docname

// regards pixxxelschubser

for (i = app.documents.length-1; i >= 0; i--) {

var aDoc = app.documents;

aDoc.name.match(/\d{13}_v([1-5])_/);

switch (RegExp.$1) {

    case '1': v1 ();

    break;

    case '2': v2 ();

    break;

    case '3': v3 ();

    break;

    case '4': v4 ();

    break;

    case '5': v5 ();

    break;

    default: alert (txt = "Nothing found in: " + aDoc.name);

    break;

    }

}

function v1 () {

alert ("v1 found in " + aDoc.name);

// do something

return;

}

function v2 () {

alert ("v2 found in " + aDoc.name);

// do something

return;

}

function v3 () {

alert ("v3 found in " + aDoc.name);

// do something

return;

}

function v4 () {

alert ("v4 found in " + aDoc.name);

// do something

return;

}

function v5 () {

alert ("v5 found in " + aDoc.name);

// do something

return;

}

Have fun

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