- AuthorPosts
- June 19, 2009 at 6:13 pm #7418DKleinMember
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?
June 20, 2009 at 3:40 am #7420Yutaka EmuraKeymasterDKlein 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);
June 23, 2009 at 5:05 pm #7426DKleinMemberThanks, 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.jseeSo 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.June 23, 2009 at 7:40 pm #7427Yutaka EmuraKeymasterGlitch 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;
June 24, 2009 at 7:07 pm #7428DKleinMemberGlitch 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.
- AuthorPosts
- You must be logged in to reply to this topic.