how to "batch replace" for a lot of files in emeditor - emeditor

yes,I know "Batch Replace All",but
my replace list is so big,has 200+ items, i will use it in a big folder which has a lot of files.
now,emediter's behave is that use item1 in all files,then use item2 in all files.....
expected: use item1....item200 in file1,and use item1...item200 in file2
how to do it ?
I attempt use the macros(openfile,replace,closefile),but it is very slowly because open a file need 50ms
emeditor 19.9.1
var fso = new ActiveXObject("Scripting.FileSystemObject");
var files = [];
var filesHasModified = [];
function showFolderFileList(folderspec) {
var f = fso.GetFolder(folderspec);
if(/\\(doc|lib|\.git|\.idea|\.vs|dll)$/gi.test(folderspec)){
return;
}
// recurse subfolders
var subfolders = new Enumerator(f.SubFolders);
for(; !subfolders.atEnd(); subfolders.moveNext()) {
showFolderFileList((subfolders.item()).path);
}
// display all file path names.
var fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext()) {
var file = fc.item();
if(/\.(jmx|config|cs|Config|tt|ttinclude|txt|yml|java|bak|xml|cshtml|sh|yaml|js|json|md|properties)$/gi.test(file)){
files.push(file);
}
}
}
showFolderFileList('D:\\Sources.git2');
for( i in files)
{
var file = files[i];
editor.OpenFile(file);
document.selection.Replace("http://172xx","http://offline.esb.xx",eeReplaceAll,0);
document.selection.Replace("http://172xx1","http://offline.esb.xx",eeReplaceAll,0);
document.selection.Replace("http://172xx2","http://offline.esb.xx",eeReplaceAll,0);
//....200 more
if(document.Saved)
{
document.close();
}
else
{
filesHasModified.push(file);
document.Save(file);
document.close();
}
}
editor.NewFile();
document.selection.Text = filesHasModified.join("\r\n");

I will optimize Batch Replace in Files in a future version. Meanwhile, please try (normal) Batch Replace with the Search All Documents in the Group option. This is how you can do:
Update EmEditor to v19.2.2 (or later).
Open EmEditor, select Tools menu - Customize - Tab page, and select None from the When Not Fit drop-down list, and select Fix to specified with from the Width drop-down list.
Open all (or some) files with EmEditor. An easy way is to drag and drop multiple files from Windows Explorer into EmEditor.
In EmEditor, press Ctrl + H to show Replace dialog box, click Batch >>, set the Search All Open Documents in the Group, make sure the batch list is updated, and click the Batch Replace All button.
The (normal) Batch Replace will work as you expect (use item1....item200 in file1, and use item1...item200 in file2, etc.).

Related

Delete metadata descriptions with a Photoshop Script?

Is there an equivalent of deleteProperty(XMPConst.NS_DC, "description”) or some way to clear out EXIF:ImageDescription, XMP-dc:Description and IPTC:Caption-Abstract with a Photoshop Script (ie, JavaScript or AppleScript)?
I am trying to remove the tags/descriptions below from TIF, PSD and PSB images:
[EXIF:IFD0] ImageDescription
[XMP:XMP-dc] Description
[IPTC] Caption-Abstract
I can do this with Exiftool with this code:
exiftool -m -overwrite_original_in_place -EXIF:ImageDescription= -XMP-dc:Description= -IPTC:Caption-Abstract= FILE
While that works great for me, I have lots of vendors that would need this in their workflows so it would be easier for them to use an action with the Photoshop Events Manager "On Document Open", or via an Automator script (Java or AppleScript) in their workflows than installing ExifTool. Looking for some help to do this...
I don’t have much coding experience, but I found the JavaScript code below on PS-Scripts as a starting point. This code doesn't require Photoshop which I like and could be done with Automator, but it only references the one tag. Also, I don’t need to write anything to the tags as this code does (I’d prefer just to delete or wipe the content and/or tags so they don’t show up).
Code: Select allvar f = File("/c/captures/a.jpg");
setDescription(f,"My new description");
function setDescription( file, descStr ){
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", descStr );
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
}
And below is an attempt at the JavaScript that would be used as a Photoshop Event on "Open Document"; but again I don't know how to amend to ensure all 3 tags reference above are cleared:
function removeDescription() {
whatApp = String(app.name);
if(whatApp.search("Photoshop") > 0)
if(!documents.length) {
alert("There are no open documents. Please open a file to run this script.")
return;
}
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
xmp.deleteProperty(XMPConst.NS_DC, "description");
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
}
removeDescription();
Finally, below was an alternate that was tried that wipes the Description, ImageDescription and Caption-Abstract on TIFFs and PNGs on the first try, but takes running through twice to work on a PSD/PSB/JPG. I think it has to do with the interaction between Description, ImageDescription and Caption-Abstract, and the solution possibly resides with amp.setLocalizedText to nothing?
function removeMetadata() {
whatApp = String(app.name);
if(whatApp.search("Photoshop") > 0) {
if(!documents.length) {
alert("There are no open documents. Please open a file to run this script.")
return;
}
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);
if (xmp.doesArrayItemExist(XMPConst.NS_DC, "description", 1))
{
xmp.deleteArrayItem(XMPConst.NS_DC, "description", 1);
}
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
debugger
}
}
removeMetadata();
Here is an example Python script that uses the Pillow library to remove the metadata descriptions.
from PIL import Image
# Open the image file
image = Image.open('example.jpg')
# Remove the EXIF:ImageDescription metadata field
image.info.pop('EXIF:ImageDescription', None)
# Remove the XMP-dc:Description metadata field
image.info.pop('XMP-dc:Description', None)
# Remove the IPTC:Caption-Abstract metadata field
image.info.pop('IPTC:Caption-Abstract', None)
# Save the modified image file
image.save('example_modified.jpg')
Change "example.jpg" to your needs.
there may be other metadata fields that contain descriptions, depending on the specific image file format and how it was created. You may need to modify the script to remove additional fields if necessary.

Create shell script from Extendscript Toolkit

As one of the outputs from an Extendscript, I want to create a shell script which can then be executed by the user. Here is a very basic example:
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.write(contents);
shFile.close();
}
createShellScript ();
If I take the resulting file (shell.sh), run chmod +x on it to make it exectuable, and then run it, nothing happens.
If, however, I adjust the script above to create the same content but a text file – so it outputs shell.txt open the file, copy the contents into a blank document in a code editor, and save as a .sh file, and then chmod and run it, it works fine.
Why does Extendscript not produce a proper .sh file when using this method?
Thanks for any help.
S
You need to set the line feed characters to unix style. For example, shFile.lineFeed = "Unix";.
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.lineFeed = "Unix";
shFile.write(contents);
shFile.close();
}
createShellScript ();

How to indent the first line of a paragraph in CKEditor

I'm using CKEditor and I want to indent just the first line of the paragraph. What I've done before is click "Source" and edit the <p> style to include text-indent:12.7mm;, but when I click "Source" again to go back to the normal editor, my changes are gone and I have no idea why.
My preference would be to create a custom toolbar button, but I'm not sure how to do so or where to edit so that clicking a custom button would edit the <p> with the style attribute I want it to have.
Depending on which version of CKE you use, your changes most likely disappear because ether the style attribute or the text-indent style is not allowed in the content. This is due to the Allowed Content Filter feature of CKEditor, read more here: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
Like Ervald said in the comments, you can also use CSS to do this without adding the code manually - however, your targeting options are limited. Either you have to target all paragraphs or add an id or class property to your paragraph(s) and target that. Or if you use a selector like :first-child you are restricted to always having the first element indented only (which might be what you want, I don't know :D).
To use CSS like that, you have to add the relevant code to contents.css, which is the CSS file used in the Editor contents and also you have to include it wherever you output the Editor contents.
In my opinion the best solution would indeed be making a plugin that places an icon on the toolbar and that button, when clicked, would add or remove a class like "indentMePlease" to the currently active paragraph. Developing said plugin is quite simple and well documented, see the excellent example at http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1 - if you need more info or have questions about that, ask in the comments :)
If you do do that, you again need to add the "indentMePlease" style implementation in contents.css and the output page.
I've got a way to indent the first line without using style, because I'm using iReport to generate automatic reports. Jasper does not understand styles. So I assign by jQuery an onkeydown method to the main iframe of CKEditor 4.6 and I check the TAB and Shift key to do and undo the first line indentation.
// TAB
$(document).ready(function(){
startTab();
});
function startTab() {
setTimeout(function(){
var $iframe_document;
var $iframe;
$iframe_document = $('.cke_wysiwyg_frame').contents();
$iframe = $iframe_document.find('body');
$iframe.keydown(function(e){
event_onkeydown(e);
});
},300);
}
function event_onkeydown(event){
if(event.keyCode===9) { // key tab
event.preventDefault();
setTimeout(function(){
var editor = CKEDITOR.instances['editor1'], //get your CKEDITOR instance here
range = editor.getSelection().getRanges()[0],
startNode = range.startContainer,
element = startNode.$,
parent;
if(element.parentNode.tagName != 'BODY') // If you take an inner element of the paragraph, get the parentNode (P)
parent = element.parentNode;
else // If it takes BODY as parentNode, it updates the inner element
parent = element;
if(event.shiftKey) { // reverse tab
var res = parent.innerHTML.toString().split(' ');
var aux = [];
var count_space = 0;
for(var i=0;i<res.length;i++) {
// console.log(res[i]);
if(res[i] == "")
count_space++;
if(count_space > 8 || res[i] != "") {
if(!count_space > 8)
count_space = 9;
aux.push(res[i]);
}
}
parent.innerHTML = aux.join(' ');
}
else { // tab
var spaces = " ";
parent.innerHTML = spaces + parent.innerHTML;
}
},200);
}
}

Indesign server data merge

I am trying to do a data merge using Indesign Server. test.indd in the script below already has all the merge fields assigned. I only need this script to open the file, do the merge, and save the merged file. The file that gets saved is the original test.indd file, and not the merged file. I'm not sure how to access the merged file.
var myDocument = app.open(File("/C/inetpub/wwwroot/datamerge/test.indd"));
with (app.dataMergeOptions) {
linkImages = true;
removeBlankLines = false;
createNewDocument = true;
documentSize = 100;
} // (end of dataMergeOptions)
myDocument.dataMergeProperties.mergeRecords();
myDocument.save(new File("/C/inetpub/wwwroot/datamerge/mergedOutput.indd"));
myDocument.close ();
If someone can have a look and let me know what I'm missing. Or direct me in the direction I should be going.
Your dataMergeOptions tell the application to create a new document but you are saving the document in your myDocument variable which is your template. You need to either get a hold of the newly created document and save that or remove the createNewDocument option.

VS 2010: Change color of lines based on a pattern

How can I change color of lines in Visual Studio 2010 based on some custom pattern? For example, I want to change color of all lines that start with logger. . Is it possible at all?
I have ReSharper 5 installed too.
I wrote up a quick little extension to do this; since you'll very likely want to modify it, you should grab the source. The important part is the code in LayoutChanged:
void ViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
IWpfTextView view = sender as IWpfTextView;
var adornmentLayer = view.GetAdornmentLayer("HighlightLines");
foreach (var line in e.NewOrReformattedLines)
{
if (line.Extent.GetText().StartsWith("logger.", StringComparison.OrdinalIgnoreCase))
{
Rectangle rect = new Rectangle()
{
Width = view.ViewportWidth + view.MaxTextRightCoordinate,
Height = line.Height,
Fill = Brushes.AliceBlue
};
Canvas.SetTop(rect, line.Top);
Canvas.SetLeft(rect, 0);
adornmentLayer.AddAdornment(line.Extent, null, rect);
}
}
}
To build/run this, you'll need to:
Download the VS2010 SDK.
Create a new project from the editor extension templates (I usually pick Visual C# -> Extensibility -> Editor Text Adornment).
Delete all the source files it creates.
Add HighlightMatchingLines.cs to the project.
F5 to run/test.
If you want to change the brush, change the Fill = Brushes.AliceBlue line.
If you want to change what text is matched, changed the condition in the if expression.
If you want to change what file type the extension is loaded for, change the [ContentType] attribute. The "Content Types" section of this msdn page lists out some of the common ones.

Resources