• Login
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.
  • P
    Patrick Coleman
    last edited by Dec 4, 2018, 8:41 PM

    Hi,

    I’ve created a macro that I would like to run at a scheduled interval, e.g. every 15 min.

    Is there a way to schedule a macro to run?

    Thanks,
    Pat

    S 1 Reply Last reply Dec 5, 2018, 3:37 PM Reply Quote 0
    • P
      PeterJones
      last edited by Dec 4, 2018, 9:29 PM

      There isn’t a way to do that natively.

      However, there may be a way using one of the scripting plugins, like PythonScript (or the others listed below). The PythonScript help lists the various notification signals that you can trap for a callback, but I didn’t see any that appeared to be timer-based – though I may have missed one.

      As an alternative, I am sure that Python or Lua (the programming languages, independent of the PythonScript or LuaScript plugins) have some manner of setting and handling timer-based alarms. During your startup (for PythonScript, use the startup.py), set an alarm; when the alarm is handled, have it use notepad.runMenuCommand() (or equivalent) to call the macro, and then have it schedule itself (set the alarm) again. I don’t know enough Python (or Lua) to work up an example for you, sorry.

      -----

      Scripting Plugins (Links)

      • PythonScript
        • PythonScript HOME
        • PythonScript DOWNLOAD
        • HELP = Plugins > Python Script > Context-Help
        • Getting Started with Python
      • LuaScript
        • LuaScript HOME
        • LuaScript DOWNLOAD
      • jN: JavaScript for Notepad++
        • jN WIKI
        • jN DOWNLOAD
      • NppExec
      1 Reply Last reply Reply Quote 2
      • P
        Patrick Coleman
        last edited by Dec 4, 2018, 11:46 PM

        I will have to dig through PythonScript when I get some time.

        In the mean time, I use Windows and someone suggested using Windows Task Scheduler. Any idea what file or script I would have it call to run the macro?

        E 1 Reply Last reply Dec 5, 2018, 12:38 PM Reply Quote 0
        • E
          Eko palypse @Patrick Coleman
          last edited by Dec 5, 2018, 12:38 PM

          @Patrick-Coleman

          you cannot use task scheduler to start a specific macro within notepad++(npp).
          Task scheduler can only be used to start programs like npp.
          May I ask you what exactly you try to do with the macro? Maybe there is a “better” way doing it.

          Eko

          1 Reply Last reply Reply Quote 2
          • S
            Scott Sumner @Patrick Coleman
            last edited by Dec 5, 2018, 3:37 PM

            @Patrick-Coleman

            macro that I would like to run at a scheduled interval

            This Pythonscript code shows one way of doing it:

            import threading
            
            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()
            
            1 Reply Last reply Reply Quote 3
            • P
              Patrick Coleman
              last edited by Dec 8, 2018, 5:02 AM

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

              S 1 Reply Last reply Dec 8, 2018, 1:25 PM Reply Quote 0
              • G
                guy038
                last edited by Dec 8, 2018, 12:20 PM

                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

                S 1 Reply Last reply Dec 8, 2018, 1:21 PM Reply Quote 0
                • S
                  Scott Sumner @guy038
                  last edited by Dec 8, 2018, 1:21 PM

                  @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. :-)

                  D 1 Reply Last reply Dec 8, 2018, 4:39 PM Reply Quote 0
                  • S
                    Scott Sumner @Patrick Coleman
                    last edited by Scott Sumner Dec 8, 2018, 1:28 PM Dec 8, 2018, 1:25 PM

                    @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
                    • D
                      dinkumoil @Scott Sumner
                      last edited by Dec 8, 2018, 4:39 PM

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

                      S 1 Reply Last reply Dec 8, 2018, 4:42 PM Reply Quote 2
                      • S
                        Scott Sumner @dinkumoil
                        last edited by Scott Sumner Dec 8, 2018, 4:43 PM Dec 8, 2018, 4:42 PM

                        @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
                        • D
                          dinkumoil
                          last edited by Dec 8, 2018, 4:44 PM

                          @Scott-Sumner said:

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

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

                          S 2 Replies Last reply Dec 8, 2018, 4:50 PM Reply Quote 1
                          • S
                            Scott Sumner @dinkumoil
                            last edited by Scott Sumner Dec 8, 2018, 4:50 PM Dec 8, 2018, 4:50 PM

                            @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
                            • S
                              Scott Sumner @dinkumoil
                              last edited by Dec 10, 2018, 1:28 PM

                              @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
                              • D
                                dinkumoil
                                last edited by Dec 10, 2018, 1:54 PM

                                @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
                                4 out of 15
                                • First post
                                  4/15
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors