SourceForge.net
2008-07-13 13:40:23 UTC
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=5093153
By: d-wachss
I don't know if this will help others, but it made my life much easier.
I was frustrated with the limitations of the macro system, but didn't want to
program my own plugins for simple things, but I realized that the Run menu will
run anything that you can use in Shell.Run
(http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx), including script
files for Windows Script Host, and that script can use SendKeys
(http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx) to communicate
back to Notepad++.
So, for example, a simple script to wrap text in a <span> tag would be:
var s = WScript.Arguments(0);
WScript.CreateObject("WScript.Shell").SendKeys('<span>' + s + '</span>');
Save it as a .js file (say, "span.js") and enter the following in the Run...
dialog:
"path/to/span.js" "$(CURRENT_WORD)"
and save it, and voila! instant javascript macro.
Obviously, this is more useful with more sophisticated scripts, and you have
to read the SendKeys documentation for the special characters and escape codes.
You probably want to include a line like
s = s.replace(/([[+^%{}\]])/g, '{$1}').replace('\n', '{ENTER}').replace('\t',
'{TAB}');
to avoid problems.
You can use any language that WSH understands, like VBScript or even Perl
(http://www.xav.com/perl/Components/Windows/PerlScript.html)
______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753
https://sourceforge.net/forum/message.php?msg_id=5093153
By: d-wachss
I don't know if this will help others, but it made my life much easier.
I was frustrated with the limitations of the macro system, but didn't want to
program my own plugins for simple things, but I realized that the Run menu will
run anything that you can use in Shell.Run
(http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx), including script
files for Windows Script Host, and that script can use SendKeys
(http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx) to communicate
back to Notepad++.
So, for example, a simple script to wrap text in a <span> tag would be:
var s = WScript.Arguments(0);
WScript.CreateObject("WScript.Shell").SendKeys('<span>' + s + '</span>');
Save it as a .js file (say, "span.js") and enter the following in the Run...
dialog:
"path/to/span.js" "$(CURRENT_WORD)"
and save it, and voila! instant javascript macro.
Obviously, this is more useful with more sophisticated scripts, and you have
to read the SendKeys documentation for the special characters and escape codes.
You probably want to include a line like
s = s.replace(/([[+^%{}\]])/g, '{$1}').replace('\n', '{ENTER}').replace('\t',
'{TAB}');
to avoid problems.
You can use any language that WSH understands, like VBScript or even Perl
(http://www.xav.com/perl/Components/Windows/PerlScript.html)
______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753