• Login
Community
  • Login

macro that pastes string value of clipboard to the search box, searches for results and pastes all lines of results to clipboard

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 936 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    Dimitris Theocharidis
    last edited by May 28, 2022, 2:13 PM

    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!

    A 1 Reply Last reply May 28, 2022, 3:06 PM Reply Quote 0
    • A
      Alan Kilborn @Dimitris Theocharidis
      last edited by May 28, 2022, 3:06 PM

      @dimitris-theocharidis

      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.

      D 2 Replies Last reply Jun 3, 2022, 12:46 PM Reply Quote 2
      • D
        Dimitris Theocharidis @Alan Kilborn
        last edited by Dimitris Theocharidis Jun 3, 2022, 12:46 PM Jun 3, 2022, 12:46 PM

        @alan-kilborn I see - I thought it was easier, something like vba in excel. Anyhow, thank you for your reply, I will consider it.

        1 Reply Last reply Reply Quote 0
        • A
          Alan Kilborn
          last edited by Alan Kilborn Jun 3, 2022, 2:49 PM Jun 3, 2022, 2:48 PM

          @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()
          
          1 Reply Last reply Reply Quote 2
          • D
            Dimitris Theocharidis @Alan Kilborn
            last edited by Jun 6, 2022, 11:27 AM

            @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!

            1 Reply Last reply Reply Quote 1
            • O
              ooan lena
              last edited by Jun 6, 2022, 5:09 PM

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              5 out of 6
              • First post
                5/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors