You are here: PSPad forum > English discussion forum > How to automate many different replaces in PSPad?

How to automate many different replaces in PSPad?

#1 How to automate many different replaces in PSPad?

Posted by: therium | Date: 08/27/2017 16:13 | IP: IP Logged

Hi,
I have about 10 files where I have to make about 10 different replaces, replacing "smart double quotes" with low-ascii equivalent. I would like to just run a single command containing all these replaces when I first edit a file. The file is markdown and I will also be using regex to do other replaces like to convert footnotes to Markdown footnotes, like:

"[24]" converts to "[^ch01-24]".

Can PSpad do this some how? I don't want to use the macro recorder because if I get one thing wrong, I have to re-record from the beginning again, and that's a PITA.

Or is there an addon/extension to do this in PSPad?

Thanks.

Options: Reply | Quote | Up ^


#2 Re: How to automate many different replaces in PSPad?

Posted by: pspad | Date: 08/27/2017 18:05 | IP: IP Logged

Hello. Look at user convertor. Pspad 5 supports regular exceptions. In the convertor folder is file Template.in_ with some description

Options: Reply | Quote | Up ^


#3 Re: How to automate many different replaces in PSPad?

Posted by: Andreas | Date: 08/28/2017 14:33 | IP: IP Logged

But we only can do this with a single file, right?

Options: Reply | Quote | Up ^


#4 Re: How to automate many different replaces in PSPad?

Posted by: pspad | Date: 08/28/2017 16:26 | IP: IP Logged

With script ypu can run convertor for all open files. As example use print all script and exchange pspad command

Options: Reply | Quote | Up ^


#5 Re: How to automate many different replaces in PSPad?

Posted by: vbr | Date: 08/29/2017 11:37 | IP: IP Logged

therium:
Hi,
I have about 10 files where I have to make about 10 different replaces, replacing "smart double quotes" with low-ascii equivalent. I would like to just run a single command containing all these replaces when I first edit a file. The file is markdown and I will also be using regex to do other replaces like to convert footnotes to Markdown footnotes, like:

"[24]" converts to "[^ch01-24]".

Can PSpad do this some how? I don't want to use the macro recorder because if I get one thing wrong, I have to re-record from the beginning again, and that's a PITA.

Or is there an addon/extension to do this in PSPad?

Thanks.

Hi,
You can use a custom script for such repeated tasks.
Just check:
Program settings: [x] System integration: Integrated scripting support (WSH)

There is a documentation in the PSPad folder
...\PSPad\Scripting.rtf
including a sample file in vbscript for running a converter on all open files;
You can group the respecive files with sessions or as a project.

Alternatively, if you prefer to have a single batch-like file to manage such conversions, it can be via scripting entirely.
Just save the javascript (preferably utf-8 encoded) e.g. as:

...\PSPad\Script\JScript\batch_conversion_re.js

Quote:
var module_name = "BatchConversionRE";
var module_ver = "1";

function reBatchReplaceMultiple(){
var fileList = ["C:\\path\\to\\a.txt","C:\\path\\to\\z.txt","C:\\path\\to\\b.txt","C:\\path\\to\\c.txt"]; // paths with double backslashes
for (var i=0; i < fileList.length; i++){
var filePath = fileList[i];
var actEd = newEditor();
try{
actEd.openFile(filePath);
}catch(e){
continue; // skip missing files
}
var outputTxt = actEd.text(); // replacements on the whole text
//series of replacements
outputTxt = outputTxt.replace(/[“”„“]/gi, "\"");//quote as needed: slashes in search patterns \/ quotes in replacement patterns: \"
outputTxt = outputTxt.replace(/[‘’]/gi, "'");
outputTxt = outputTxt.replace(/\[(\d+)\]/gi, "[^ch01-$1]");
actEd.text(outputTxt);
actEd.setCaretPos(0,0);
actEd.saveFile(); // (un)comment as needed
// actEd.closeFile(); // (un)comment as needed
}
}

function Init(){
addMenuItem("Multiple batch replace RE", "", "reBatchReplaceMultiple","Ctrl+Alt+Shift+H");
}

After saving the script file in the mentioned location, you have to call Scripts: Recompile scripts, and the menu item should appear whithin scripts (and the shortcut is assigned).

The script should be tweaked to match your data, paths and needed conversion; you can assign another shortcut too (provided there is no collision with system,program, code clips or other scripts' shortcuts).

hth,
vbr

Options: Reply | Quote | Up ^


#6 Re: How to automate many different replaces in PSPad?

Posted by: therium | Date: 09/13/2017 15:13 | IP: IP Logged

Thank you. Is that VBScript you gave me?

Options: Reply | Quote | Up ^


#7 Re: How to automate many different replaces in PSPad?

Posted by: vbr | Date: 09/13/2017 16:05 | IP: IP Logged

therium:
Thank you. Is that VBScript you gave me?

Hi, You are welcome;
it is javascript; like VBScript, it should be supported by default on windows WSH.
The script file must be placed in the appropriate folder, e.g.:
... Script\JScript\
(either in PSPad Program folder or possibly in the user profile folder).
hth,
vbr

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2017 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák