#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.