macro that pastes string value of clipboard to the search box, searches for results and pastes all lines of results to clipboard
-
Hello everyone from Greece!
As I try to record my own macro, it seems that I cant find the way to make notepad++ get the CURRENT value from the clipboard in order to paste it to the search box. (It uses the string that was in the clipboard the very first time I tried the idea).
Moreover, I need all lines of these results to copy and paste in the clipboard.
I tried to select them by marks and simultaneous bookmarks but I cant find a way to record the action of copying these into clipboard.
Any ideas? Thank you for your time! -
What you’re describing I don’t think is possible with only the use of macros. It is much more achieveable with scripting, but not sure you’d be comfortable with such a solution (requires the use of a scripting plugin and some programming – which we could help you with). If you want to go that route, let us know.
-
@alan-kilborn I see - I thought it was easier, something like vba in excel. Anyhow, thank you for your reply, I will consider it.
-
@dimitris-theocharidis said in macro that pastes string value of clipboard to the search box, searches for results and pastes all lines of results to clipboard:
I thought it was easier, something like vba in excel
Well… it isn’t exactly like that, but programming is programming is programming…
As an example of how “easy” it is, I’ve coded up your request into a PythonScript that I called
SearchCurrDocForClipboardTextThenCopyMatchingLines.py
:# -*- coding: utf-8 -*- from __future__ import print_function import inspect import os #------------------------------------------------------------------------------- try: editor3h # third editor, hidden except NameError: editor3h = notepad.createScintilla() def clipboard_get_text(): editor3h.clearAll() editor3h.paste() retval = editor3h.getText() return retval #------------------------------------------------------------------------------- class SCDFCTTCML(object): def __init__(self): self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0] text_to_find = clipboard_get_text() if len(text_to_find) == 0 or len(text_to_find) > 2046: self.mb('Inappropriate find-what in clipboard') return regex = r'(?-is)^.*?\Q' + text_to_find + r'\E.*' matches_list = [] editor.research(regex, lambda m: matches_list.append(m.span(0))) line_content_list = [ editor.getTextRange(s, e) for (s, e) in matches_list ] editor.copyText('\r\n'.join(line_content_list)) def mb(self, msg, flags=0, title=''): # a message-box function return notepad.messageBox(msg, title if title else self.this_script_name, flags) #------------------------------------------------------------------------------- if __name__ == '__main__': SCDFCTTCML()
-
@alan-kilborn I have just tried your work. Fantastic!!! Thank you very much for your time!!! Hope life is generous with you, as much as you are with strangers! Thank you again!
-
This post is deleted!