Community
    • Login

    Automate/Schedule a Macro

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 6 Posters 4.6k 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.
    • Patrick ColemanP
      Patrick Coleman
      last edited by

      @Scott-Sumner said:

      def timer_callback():
      print(‘hello world every 3 seconds!’) # or, for example, notepad.runMenuCommand(menuName, menuOption)
      threading.Timer(3.0, timer_callback).start()

      timer_callback()

      Hi Scott,

      I tried your script as follows:

      def timer_callback():
      notepad.runMenuCommand(Macro, my-macro)
      threading.Timer(3.0, timer_callback).start()

      timer_callback()

      I am getting “NameError: name ‘notepad’ is not defined.”

      Any thoughts on how to resolve that?

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by

        Hi, @patrick-coleman, @scott-sumner and All,

        Just a piece of information :

        When you want to execute a Windows program or batch script, on specific intervals, the Microsoft schtasks utility is quite powerful ;-))

        For instance, the line, below, typed in a console windows, would create a task, named Test which executes the test.bat batch, located in \D: every minute :

        schtasks /create /sc minute /mo 1 /tn "Test" /tr D:\test.bat

        For help on this command, which replaces, the old at command, type in schtasks /?

        To list all the scheduled tasks, simply type schtasks and valid

        To delete the Test task, type in the command schtasks /delete /tn test


        Here is, below, the detail of the schtasks command ( Sorry, it’s written in French on my system, of course ! )

        SCHTASKS /paramètre [arguments]
        
        Description :
            Permet à un administrateur de créer, supprimer, effectuer des requêtes, modifier, exécuter et
            mettre fin à des tâches planifiées sur un système local ou distant. Remplace AT.exe.
        
        Liste de paramètres :
            /Create         Crée une nouvelle tâche planifiée.
        
            /Delete         Supprime les tâches planifiées.
        
            /Query          Affiche toutes les tâches planifiées.
        
            /Change         Modifie les propriétés d'une tâche planifiée.
        
            /Run            Exécute la tâche planifiée immédiatement.
        
            /End            Arrête la tâche planifiée actuellement en cours d'exécution.
        
            /?                             Affiche cet écran d'aide.
        
        Exemples :
            SCHTASKS
            SCHTASKS /?
            SCHTASKS /Run /?
            SCHTASKS /End /?
            SCHTASKS /Create /?
            SCHTASKS /Delete /?
            SCHTASKS /Query  /?
            SCHTASKS /Change /?
        

        Well, now the deal is how to connect that stuff with the action of running a macro from within N++ ;-)) Not tried, yet !

        Best Regards,

        guy038

        Scott SumnerS 1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner @guy038
          last edited by

          @guy038 said:

          Well, now the deal is how to connect that stuff with the action of running a macro from within N++ ;-)) Not tried, yet !

          Yea…good luck. I’ll look forward to seeing the solution on THAT one. :-)

          dinkumoilD 1 Reply Last reply Reply Quote 0
          • Scott SumnerS
            Scott Sumner @Patrick Coleman
            last edited by Scott Sumner

            @Patrick-Coleman said:

            I am getting “NameError: name ‘notepad’ is not defined.”

            You have to understand Python/Pythonscript a bit for this one. The short story is you probably need this at the top of the script:

            from Npp import notepad
            

            For my setup, I put that line in my startup.py (which runs upon Notepad++/Pythonscript-plugin startup, hence its name), so I don’t have to put that in my individual script files (but you can do it that way).

            1 Reply Last reply Reply Quote 1
            • dinkumoilD
              dinkumoil @Scott Sumner
              last edited by

              @Scott-Sumner said:

              I’ll look forward to seeing the solution on THAT one. :-)

              Seems it’s time for another nice hackish (though unnecessary) solution. Here we go. :-)

              1. Download and install my NppUISpy plugin. Follow the instructions for its manual installation.
              2. Download the tool NirCmd (scroll down to the end of the text to find the download links) and unpack the zip file to a directory where you have write access.
              3. Start Notepad++, go to Plugins menu and launch the NppUISpy plugin by clicking on its Spy! menu entry.
              4. In the left pane of the plugin’s UI go to the tree node of the Macro menu and open it by clicking on the small + sign to its left. Find the entry of the macro you want to start and remember the related number in the Command Id column. Please note: The tree items respond to mouse clicks and make Notepad++ to execute the related command. Maybe you prefer to click only on the tree lines at the left and the small + signs to prevent that. The toolbar button items in the right pane respond to mouse clicks as well.
              5. Start a console window and navigate to the directory where you have unpacked NirCmd.
              6. Type the following command: nircmdc win postmsg ititle "Notepad++" 2072 0 XXXXX where XXXXX is the number you remembered in step 4.

              The command of step 6 can be put into a batch file which in turn can be executed by a scheduled task.

              Scott SumnerS 1 Reply Last reply Reply Quote 2
              • Scott SumnerS
                Scott Sumner @dinkumoil
                last edited by Scott Sumner

                @dinkumoil

                I knew it was going to get wild and crazy like that. :-)

                It’s fine though as there is a Notepad++ tie in, so we are not getting into “off-topic” land…

                Curious, though, why did you say “(though unnecessary)”…?

                1 Reply Last reply Reply Quote 0
                • dinkumoilD
                  dinkumoil
                  last edited by

                  @Scott-Sumner said:

                  Curious, though, why did you say “(though unnecessary)”…?

                  Because you have already posted a (I guess) working Python solution.

                  Scott SumnerS 2 Replies Last reply Reply Quote 1
                  • Scott SumnerS
                    Scott Sumner @dinkumoil
                    last edited by Scott Sumner

                    @dinkumoil

                    I see. Well, we don’t know yet that the Pythonscript-based solution will work for the OP, so it is still nice to have other options. BTW, I like the looks of your “spy” plugin! (see…without the alternative solution path being presented, I never would have learned about that plugin!)

                    1 Reply Last reply Reply Quote 2
                    • Scott SumnerS
                      Scott Sumner @dinkumoil
                      last edited by

                      @dinkumoil

                      Does the “spy” plugin take a large amount of time to initialize when it starts up? I added it to my setup and it seems to have some odd interactions with some of my Pythonscript stuff that runs on startup. I haven’t investigated further yet but the first thing I noticed is that it seems to take longer now for my Notepad++ to get to a “ready for editing” state.

                      1 Reply Last reply Reply Quote 0
                      • dinkumoilD
                        dinkumoil
                        last edited by

                        @Scott-Sumner

                        Hmm, the plugin itself does nearly nothing when it is loaded, it only adds its menu entries to the Notepad++ UI. Only when you click on the Spy! menu entry it examines the main menu and the toolbar of Notepad++ and fills its trees. All these data gets thrown away when you close the dialog.

                        But it is a Delphi application and as such it incorporates the needed parts of the VCL (Visual Component Library), the abstraction layer of Delphi for the Win32 API. In this context it loads a noticeable amount of Windows DLL files. Maybe this causes the increased load time.

                        I have installed about to 45 plugins, thus my Notepad++ needs some time to start up anyway and I was not aware of an increased load time after adding the new plugin.

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors