Startup script that make layer visible depending on docs filename

Home Forums General InDesign Topics Startup script that make layer visible depending on docs filename

This topic contains 1 reply, has 1 voice, and was last updated by  Jonas Ericsson 2 years, 1 month ago.

  • Author
    Posts
  • #68922

    Hi,
    First: I’m a newbie when it comes to scripting.
    The Guru himself, Peter Kahrel helped me to write another script that has the name.search in it and I reused some of it here.

    I have started to wrote a startup script that set “visible = true” on a specific layer if the document starts with a specific filename. If the first layer doesn’t exist, try “xxx” in the first name.search.
    And if the first “name.search” does’nt match I want the script to test the next “name.search”, and the next…

    The problem I have is that only the first name.search “kicks” in.

    How to make the script check the other name.search-lines?

    #targetengine “session”

    main();
    function main(){
    var myEventListener = app.eventListeners.add(“afterOpen”, excuteScript);
    }

    function excuteScript(){
    var myD = app.documents[0];

    // if filename starts with ABA (and perhaps 1 more letter) and contains 8 numbers, 3 letters, 2 (or 3) numbers plus.indd
    if (myD.name.search(/^\ABA\w?-\d{8}(-\w\w\w)?-\d{2}\d?\.indd/i) == -1) return
    try{
    var mittLager = myD.layers.item(“AB_serier”);
    mittLager.visible = true;
    }
    catch (myError){
    var mittLager = myD.layers.item(“AB_kryss”);
    mittLager.visible = true;
    }

    // if filename starts with OOA (and perhaps 1 more letter) and contains 8 numbers, 3 letters, 2 (or 3) numbers plus.indd
    if (myD.name.search(/^\OOA\w?-\d{8}(-\w\w\w)?-\d{2}\d?\.indd/i) == -1) return
    try{
    var mittLager = myD.layers.item(“AM_OA_serier”);
    mittLager.visible = true;
    }
    catch (myError){
    var mittLager = myD.layers.item(“AM_OA_kryss”);
    mittLager.visible = true;
    }

    // if filename starts with OBA (and perhaps 1 more letter) and contains 8 numbers, 3 letters, 2 (or 3) numbers plus.indd
    if (myD.name.search(/^\OBA\w?-\d{8}(-\w\w\w)?-\d{2}\d?\.indd/i) == -1) return
    try{
    var mittLager = myD.layers.item(“AM_OB_serier”);
    mittLager.visible = true;
    }
    catch (myError){
    var mittLager = myD.layers.item(“AM_OB_kryss”);
    mittLager.visible = true;
    }

    }

  • #68923

    Forgott to change from swedish “mittLager” to “myLayer. Sorry

The forum ‘General InDesign Topics’ is temporarily closed to new topics and replies due to site maintenance. Please check back tomorrow.