Run the Script on the Open Document event

OK so I know about the spectacle of afterOpen and I think I understand how to use it, however, I do not understand how to open to a specific document.

I don't want this script runs on all the documents that I opened, I would like to incorporate into a document and then run it whenever I open this document. Is this possible?

Maybe run the script in the script label?

Or I just put a script in the start Panel, and then create a session script that checks the name of each document open and then runs the script, if I have a match?

Thank you

As you chart put it in the startup scripts folder

//startup script
#targetengine "session"
main();
function main(){
    var myEventListener = app.eventListeners.add("afterOpen", excuteScriptLabel);
}

function excuteScriptLabel(myEvent){
          //The parent of the event is the document.
          var myDocument = myEvent.parent;
    if (myDocument.constructor.name == "Document") {
        if (myDocument.label != "")
            app.doScript(myDocument.label, ScriptLanguage.javascript);
    }
}

Then try this line on a document and save it, and then open the same file and a few others, you will notice that this code only run on this document:

app.activeDocument.label = "alert (\"Yes\");";

Tags: InDesign

Similar Questions

  • [CS5] Run a script on the open document

    Is it possible to run a script automatically whenever a document is open?

    Application has the "beforeOpen" event listener, which won't work, the document is not opened and Document has the "afterOpen" event listener, but which cannot be added until after the document is already open, so I'm not sure was what it serves.

    Any help would be appreciated.

    /Dan

    .. .and document has the "afterOpen" event listener, but will not be added until after the document is already open, so I'm not sure what it serves.

    You can do it-here is an example:

    #targetengine "MyEngine"
    
    var myEventListener = app.eventListeners.add("afterOpen", myDocOpen, false);
    
    function myDocOpen(myEvent)
    {
         var myDoc = app.documents[0];
        myDoc.pages.add(LocationOptions.AT_END);
    }
    

    It is important to use app.documents [0] instead of app.activeDocument when you use the afterOpen event.

    This simple script adds a new page whenever a document is open. Written and tested on CS3, windows.

    Kasyan

    P.S. I just tested on CS5 - it works here as well, but it adds two pages instead of one for a reason any.

  • AppleScript/Pages can not find the open document

    This very simple script will not work:

    Tell application "Pages".

    activate

    say the document before

    name

    tell the end

    tell the end

    All of this has to do is give the name of the opened document. It says: "cannot get document 1. Invalid index. "And, Yes, there is an open document.

    This behavior deteriorated. He worked a few weeks ago and then become increasingly more broken. It's the same thing with the numbers.

    That's happened? My Applescript is corrupt?

    It works very well here:

             tell application 'Pages' to return before the document name

    And so for this:

    say application 'Pages '.

    say front document

    name

    end say

    end say

    With the keys v 5.6.1. OS X 10.11.1 (El Cap).

    Make sure you have checked it in system preferences:

    SG

  • How to remove all the images in the open documents

    Hi, experts

    How this script works out all the images in the open documents?

    function re() {}

    var link, image, image;
    var openDocs = app.documents.
    var openDocsLen = openDocs.length;
    for (var d = 0; d < openDocsLen; d ++) {}
    currDoc = openDocs [d],
    Links = currDoc.links,.
    counter = 0;
    for (var i = links.length - 1; i > = 0; i--) {}
    If (links [i] == docs.links) {}
    try {}
    link = links [i];
    image = link.parent;
    Frame = image.parent;
    Frame.Remove ();
    counter ++;
    }
    {} catch (err)
    $.writeln (i + "-" + err);
    }
    }
    }
    }
    }

    respect of

    John

    Dear John,

    Try your code updated.

    Re();

    function re() {}

    var link, image, image;

    var openDocs = app.documents.

    var openDocsLen = openDocs.length;

    for (var d = 0; d)< opendocslen;="" d="">

    currDoc = openDocs [d],

    Links = currDoc.links,.

    counter = 0;

    for (var i = links.length - 1; I > = 0; i--) {}

    If (links [i] .hasOwnProperty ('relink')) {}

    try {}

    link = links [i];

    image = link.parent;

    Frame = image.parent;

    Frame.Remove ();

    counter ++;

    }

    {} catch (err)

    $.writeln (i + "-" + err);

    }

    }

    }

    }

    }

    Best regards,

    K.Velprakash.

  • I'll always be able to run the opening after upgrade to El Capitan?

    I want to install Office 2016 on my MacBook Pro which is running 10.9.5 - it asks me to upgrade to El Capitan. I'm afraid that Aperture will not work more.

    On El Capitan, you need opening 3.6.  You are currently running opening 3.5.1 or an older version?

    Before you upgrade to el Capitan make a full time Machine backup of you system so that you can return to the Mavericks, if need to be.  (see: OS X El Capitan: revert to a previous version of OS X)

    And check if you are able to update to 3.6 opening.  Check before upgrade you to El Capitan.

    • Open the App Store and sing in your account in the Store with your AppleID menu.
    • The fourth "shopping" tab  Figure opening it to your purchase history?  If so, you can update opening 3.6, once you have upgraded to El Capitan.  If the opening is absent from your purchase history, you will only be able to update with the help of the PapSTore supported.

    See this user Tip: update to Aperture 3.6 after the release of Photos

    https://discussions.Apple.com/docs/doc-8402

    3.6 the opening is the latest version of Aperture and the only one to run on El Capitan.

    There are more and more questions with an opening. Opening 3.6 is running on El Capitan, but keep accumulating the minor bugs.

    • When brushing the adjustments, the position may be a bit off, a pixel or so.
    • The thumbnails in the list view are backwards.  Re: opening and El Capitan OSX
    • If you add a curves adjustment, adjustment to straighten will be not visible in the exported images. See: right
    • The link to the plug-ins page work is no longer in the opening menu, but it's the same for all versions.

    And you can order are no longer produced printouts of Aperture. Apple has stopped completely, the support for Aperture print products in any version of Aperture.

  • How to get the "Open Document" link

    Dear friends,

    I adapted a Notification of application based on the PL/SQL documents and workflow concepts.

    I created the number of applications to test. Each request to have 3 people involved say A, B, C

    One for presentation, two others for approval.

    After approval of the person (B), it will go to c. up to now, everything works fine.

    But in the list of person C of notification, the link titled 'Open Document' is missing to open the application.

    What do I need TO CONFIGURE SOMETHING.

    How to solve this problem. Any idea. Please share.

    Let me know for any clarification.

    Thank you

    Aravinda.

    Dear friends

    It is resolved.

    Just add purchase responsibility of the user to whom this 'open document link"is not visible in the notification.

    Thank you

    Aravinda.

  • new document of the same size as the open document

    Is it possible to be on a layer and just copy this layer in a new file without having to create and resize the new file to match and then pull the layer in the new file? It sounds like these tedious process, especialy if it must be done several times in a work session. I can't find a menu option to do.

    Thank you

    Hi jjaylad,

    Yes, you can do a right click or command by clicking on this layer and choose Duplicate layer then, click New in the document drop.

    Kind regards

    Claes

  • Run the VI command line in Windows 7

    I try to open a VI and do it run whenever called from the command line.  I am running Windows 7 and LabVIEW 2009.

    I followed this guide to get me started.

    First, I marked my VI "run the opening:

    I therefore call on my command prompt similar program:

    "C:/Program Files/National Instruments/LabVIEW 2009/LabVIEW.exe" "C:/User/Desktop/test.vi"
    

    If I already open LabVIEW and running in the main menu, then it opens my VI perfectly without any problems.

    However, if I don't already have LabVIEW open, it opens LabVIEW as she normally does, but it only loads to the main menu.  It doesn't load any of my VI.

    Does anyone know if this is expected behavior, or how can I fix this so that it opens upward Although LabVIEW is currently closed?

    Well... I managed to do work haha.  If you come to ignore the document and open the file via the command line, it opens fine.  I don't know why they say that you can use the command line argument LabVIEW.exe.

    "C:\User\Desktop\test.vi"
    
  • Script to copy layer in another open Document/group?

    Hi, I know that this topic has been covered several times before. But to clarify, here's what I asked:

    Copy the active layer/group into another document opened in Photoshop. The easiest way is to go to the «layer/double layer...» ». But it is very tedious. To begin with, when you choose this method and then select the document you want to copy in the menu drop-down, successfully, copy the layer/group for this document, but it is not auto-switch (unlock) in the document, he just copied in. You have to hit 'Ok', and then manually search through the open documents list via (window / * choose your document *) to get there. It is a nightmare when you try to do several times.

    Here's what I asked:

    It is possible to:

    (a) copy the active layer/group in the Clipboard/memory

    (b) switch to another document in Photoshop * via a personalized menu * which shows all existing documents

    (c) one time positioned on the new document, paste this layer/group from the Clipboard into this document

    .. is this possible?

    At the very least, is there scripts that anyone knows of that allows the user to switch between existing documents via a custom instead of going to the window menu / * choose your document *?

    Hi @boo radley 2013.

    do you mean something like this?

    // LayerPaste2anotherDoc.jsx
    // https://forums.adobe.com/thread/1496531
    
    // regards pixxxelschubser
    
    var aDoc = app.activeDocument;
    var AllDocs = app.documents;
    var actLay = aDoc.activeLayer;
    
    if (AllDocs.length > 1) {
    var itemDoc = null;
    actLay.copy ();
    
    var win = new Window("dialog","Copy the active layer");
    this.windowRef = win;
    win.Txt1 = win.add ("statictext", undefined, "Paste in which open document?");
    win.NewList=win.add ("dropdownlist", undefined, AllDocs);
    
    win.NewList.selection = 0;
    itemDoc = win.NewList.selection.index;
    
    win.cancelBtn = win.add("button", undefined, "Abbruch");
    win.quitBtn = win.add("button", undefined, "Ok");
    win.defaultElement = win.quitBtn;
    win.cancelElement = win.cancelBtn;
    win.quitBtn.onClick = function() {
    win.close();
    }
    
    win.NewList.onChange= function () {
        itemDoc = win.NewList.selection.index;
        return itemDoc;
        }
    
    win.show();
    
    app.activeDocument = app.documents[itemDoc];
    app.activeDocument.paste();
    app.refresh();
    } else {
        alert ("No other documents open")
        }
    

    Have fun

  • Is it possible to import image files directly into an open document?

    Is it possible to import a series of image files, say jpegs, directly in an open document, rather than having to open all image files with drag-and - move each individual in the open document? Specifically, I'm a dentist and I often get sent to me by other offices digital x-ray images. But they come as 16 or 18 separate image files and I need to put them in a virtual "chest x-ray: mount", so I can see them all at once, rather than having to open all images and alternate between them. So I opened a blank document in PS (CS4), then I navigate to the folder that contains all the image files that I received, select all and open them all. In PS, I can now click on each tab of the image and drag the image into the void "montage" and close the image. This new image would then become its own layer in the document 'mount '. But I must repeat this 18 times for each patient. I thought that if there was a way to open the new document "mount" and then select all of the image files and 'import' somehow all image directly in the document - essentially "automate" - which would save me time and aggravation cargo! Anyone out there have any suggestions? Thank you very much!! Dr G.

    Yes, but after you have all your images as layers in a new document, that you can simply select all the layers of-> and then drag them to your document in one fell swoop.

  • Switch between open documents?

    Hi all

    Is there a keyboard shortcut (or the way to create a custom shortcut) to switch between open documents in DW? What I speak is something similar to Alt - Tab on Windows. When I am using the code keyboard it would be awfully nice to quickly switch to another open rather file to reach for the mouse each time.

    I hope that it is something that I simply not ran through again in 3 different improvements of DW and not something that the program can't do.

    Thank you!

    Ellie

    choirellie wrote:
    > Hi all,
    >
    > Y at - it a keyboard shortcut (or the way to create a custom shortcut) allowing you to alternate
    > open between the two documents in DW? What I will speak about is something similar to
    > Alt - Tab on Windows. When I work on coding the keyboard, it would be
    > terribly nice to quickly switch to another file open rather than to achieve a
    > the mouse each time.

    It is built in: CTRL + TAB moves from left to right and CTRL + SHIFT + TAB moves from right to left. I think it may be CMD +' for Mac, but not sure.

    Unfortunately, in CS$, I was not able to find a shortcut to switch between the associated files in the open document active, in addition to the "long" lane: ALT + V, taking hit ALT R twice, then arrow key right, then signs upward or down to the next file to.

    --
    Danilo Micen
    | http://blog.Extensioneering.com/
    | Extensioneer WebAssist
    | Adobe Community Expert

  • Y at - he opened a Java command/script that runs all calculations in a PDF document on the document?

    Long story short, design a timesheet for my company using Adobe Pro. The form has fields that use java script to calculate different values. For example when someone enters the week, finishing, it fills the rest of the form with the correct days. This is a simple script which is located in "custom calculation. It works fine on PC and iOS devices (when you use a PDF reader application) but not when calculating on Android devices. When opened on a PC then the dates have not been calculated. This seems to be a problem with the Android device and the way it handles the script embedded in the page. For the test I used Adobes PDF reader program so in theory, these functions must be activated. However, I find very little information on why this would happen. For me that a simple work-around would be to set the properties of the document just run all calculations on the open page. So when opened on a PC by our payroll service dates will fill up. If you are curious of the code that I use I have attached below.

    Thank you in advance.

    The script:

    Custom text field calculation script

    (function () {}

    Get the value of the ZZWEEKEND field

    var v = getField("ZZWEEKEND").value;

    If the field is blank, this field blank

    if (v === "") {

    Event.Value = v;

    return;

    }

    Convert string to date in a date object

    var d = util.scand ("mm/dd/yyyy", v);

    Subtract the number of days

    d.setDate (d.getDate () - 4);

    Set the value of this field

    Event.Value = util.printd ("mmm - dd", d);

    })();

    You can use the calculateNow method, for example:

    calculateNow();

    in a script Page Open.

  • Script button to open the attachment Panel and attach the document

    Y at - it a button click script that will open the attachment Panel and the pop-up navigation window to select a document to be attached?

    The script to open the attachment is:

    event.target.viewState = {overViewMode:7};

  • Photoshop script to copy all the layers of close PSD to open the current document

    Hi, I have very limited capacity script so this task is above my pay grade

    I'm looking for a script to read and copy all the layers in a PSD saved file and copy them into the current active document. The two documents have the same size and I need to be able to change text layers after copying. Anyone has any advice or examples of how I might be able to do this?

    Thank you in advance for any help you can offer.

    Kind regards

    Marcus

    Try the script in entry below. You must open the destination file, and you must put in the path and name where your source file. It will not choose a layer from background from the source file.

    #target photoshop
    var sFile = new File('~/desktop/template.psd');//change path to template file
    var doc = activeDocument;
    var sDoc = open(sFile);
    
    var idselectAllLayers = stringIDToTypeID( "selectAllLayers" );
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref1.putEnumerated( idLyr, idOrdn, idTrgt );
        desc2.putReference( idnull, ref1 );
    executeAction( idselectAllLayers, desc2, DialogModes.NO );
    
    var idDplc = charIDToTypeID( "Dplc" );
        var desc5 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref2 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref2.putEnumerated( idLyr, idOrdn, idTrgt );
        desc5.putReference( idnull, ref2 );
        var idT = charIDToTypeID( "T  " );
            var ref3 = new ActionReference();
            var idDcmn = charIDToTypeID( "Dcmn" );
            ref3.putName( idDcmn, doc.name );
        desc5.putReference( idT, ref3 );
        var idVrsn = charIDToTypeID( "Vrsn" );
        desc5.putInteger( idVrsn, 5 );
        var idIdnt = charIDToTypeID( "Idnt" );
            var list1 = new ActionList();
            list1.putInteger( 3 );
            list1.putInteger( 4 );
        desc5.putList( idIdnt, list1 );
    executeAction( idDplc, desc5, DialogModes.NO );
    
  • Run the Script before the opening of Outlook 2010

    We have a command to run to load an add-in in Outlook before you open it.   Us thinapp Office and it works very well but we have to find a way to run the script once when they first open Outlook.  Does anyone know a good way to do this?  I got to the point where I created a shortcut under Office tools to run the script manually but I want it to be transparent to the user.

    Basically, we need run the following command to load the add-in.

    servername AppInstall.exe

    Try using VB script. For examples, see here:

    Writing scripts in ThinApp | VMware ThinApp Blog - Articles from VMware

Maybe you are looking for

  • Retrigger AO finished on PCIe-6321?

    Hello! As indicated in the subject, I would like to generate an output on the card PCIe-6321 analog redeclenchables finished-samples (X series). I wired faithful to start: redeclenchables enter the node property trigger, but the AO task runs that onc

  • Photosmart c410a: Windows Solution Center 10

    After the update to windows 10 HP solution Center does not work. When I run the installer supplied with the printer it just asking you to leave me. When I try to download the drtiver of the support.hp.com, it says that the page is not found. Y at - i

  • Microsoft lifecam hd-5000 problem Installtion

    My system is Windows xp home edition. I have uppluged and reconnected to my usb port several times, tried different 2.0 ports, connected my old webcam and recognized computer, restarted my computer several times and reinstalled at least four times. I

  • Can not be logged as an administrator

    I've been running XP with no one else that me as administrator, with no named users, I received a message that I wanted to change him compelled me to be logged in as an administrator to try to see how I was really connected, I added a new user and as

  • e9110t Power Supply Upgrade

    Good, finally found the power mentioned in my last thread and is been installed today. The only thing is that nothing lights up. Am I missing something? I reconnected it allt he same points with old food and here I am able to use my computer. It coul