Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #7418

    DKlein
    Member

    I can run a macro on a file from the command line; but then, I’d like EmEditor to save and close down. Then I could put that line into a batch file with other commands and the user wouldn’t have to close EMEditor. Maybe there is a macro command to close EM?

    #7420

    Yutaka Emura
    Keymaster

    DKlein wrote:
    I can run a macro on a file from the command line; but then, I’d like EmEditor to save and close down. Then I could put that line into a batch file with other commands and the user wouldn’t have to close EMEditor. Maybe there is a macro command to close EM?

    Please try this:


    editor.ExecuteCommandByID(4119);

    http://www.emeditor.com/help/cmd/file/exit_all.htm

    #7426

    DKlein
    Member

    Thanks, pretty cool. Just two little gliches left.

    So I can make a batch job named EMB.BAT that contains:
    “c:program filesemeditoremeditor.exe” \%1 /sp /cd /mf \%2.jsee

    So the user can type on the command line: EMB infile macroname
    The macro runs on the file and returns to the command line prompt.

    The macro is:
    // If the line contains a “tag” of any length starting at TagStart
    // Replace occurrences of SearchText with ReplaceText if in the column “window”.
    //
    // User modifies these settings:
    Tag = “020”;
    TagStart = 1;
    SearchText = “Kl”;
    ReplaceText = “Sss”;
    WindowStart = 4;
    WindowEnd = 14;
    //
    if( !editor.EnableTab ){
    editor.EnableTab = true;
    alert( “Enabling tab for editor. Please restart micro.” );
    Quit();
    }
    if (WindowStart > WindowEnd)
    {
    alert (“Window Start greater than Window End”);
    Quit();
    }
    if (SearchText.length > WindowEnd – WindowStart + 1)
    {
    alert (“Search term length is greater than the Window”);
    Quit();
    }
    windowStop = WindowEnd – SearchText.length + 2;
    document.selection.StartofDocument();
    y = 1;
    replacements = 0;
    do
    {
    // Move to next line; then at EOF if can’t get the active location
    document.selection.SetActivePoint( eePosView, 1, y );
    if( y != document.selection.GetActivePointY( eePosView ) ) break;
    document.selection.SetActivePoint (eePosView, TagStart, y, true);
    document.selection.SetActivePoint (eePosView, TagStart + Tag.length , y, true);
    if( document.selection.Text == Tag )
    {
    windowIndex = WindowStart;
    do
    {
    document.selection.SetActivePoint( eePosView, windowIndex, y , false);
    document.selection.SetActivePoint( eePosView, windowIndex + SearchText.length, y , true);
    if ( document.selection.Text == SearchText) //If found
    {
    document.selection.Text = ReplaceText;
    replacements++;
    }
    windowIndex ++;
    } while (windowIndex < windowStop)
    }
    y++;
    } while( true );
    inFile = document.FullName;
    results = replacements + ” replacement count on ” + inFile

    // Interactive mode
    //document.selection.StartofDocument();
    //alert(results);
    //

    //Batch mode
    document.Save(inFile);
    extension = inFile.lastIndexOf(“.”);
    resultFile = inFile.substring (0, extension + 1) + “emc”;
    fso = new ActiveXObject (“Scripting.FileSystemObject”);
    s = fso.CreateTextFile(resultFile);
    s.writeline(results);
    s.Close();
    editor.ExecuteCommandByID (4119); //Close down Em

    —-
    Glitch 1:
    The first time I run the batch it shows EMEditor and askes if this is a “trusted” macro and the user has to select the Yes button. On subsiquent runs EMEdit remembers it is trusted. Anyway to avoid the prompt?

    —-
    Glitch 2:
    If EmEditor already an instance, running the batch in a Command Line instance will shut EM instance down, too. The “/sp” isn’t doing anything in the EMB job above.

    —-
    EM Editor is close to replacing application we have that runs edit commands on files.

    #7427

    Yutaka Emura
    Keymaster

    Glitch 1:
    If the macro is one of macros defined in the “My Macros” list in EmEditor, this warning will not be displayed. So before you run this first time, please select this macro to be included in the My Macros list.

    Glitch 2:
    Instead of using Close All command, you might want to use Close command using:

    document.close;

    http://www.emeditor.com/help/cmd/file/app_exit.htm

    #7428

    DKlein
    Member

    Glitch 2 is gone. Thanks.

    Glitch 1 maybe isn’t so bad. These macros will be used in a production environment (different machines will use them) and will be customized in different folders (may have the same name). Putting them into a My Macros will not work. For instance, there may be a AddProject.vsee in each customers folder that adds the unique project ID to a file with Command Line “EMC filename AddProject”.

    It appears EM must be keeping a perminate list (in the registry?) of trusted macros and the folder it is in as you only have to use the “trust” prompt the first time even after booting. This would be per machine as everybody has to trust it once. I suppose you have to do this because these macros are powerful programs and can take over the users computer. This prevents a virus starting up EM to run its bad macro.

    Thanks for our help. I’m very impressed with your responsiveness and the product in general.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone