Community
    • Login

    batch script run in place

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    2 Posts 2 Posters 134 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.
    • Chris RobertsonC
      Chris Robertson
      last edited by

      I can run my script in place, but is there a way I can save the file when I (before) I run (ctrl+s)

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Chris Robertson
        last edited by

        @Chris-Robertson ,

        You didn’t say, but for the sake of my answer, I will assume when you say “I can run my script in place”, you mean “I use the Run > Run menu command to run cmd /c "$(FILE_NAME)" (or similar) to run the active file using its default assocation” or maybe “I have saved that Run > Run command into the Run menu, and maybe have a keyboard shortcut for it”. If I have misinterpreted your statement, you will have to clarify with much more detail.

        The Notepad++ macro system can record certain actions then play them back. Unfortunately, as explained in our FAQ: Automating Notepad++, certain commands – like those from plugins, and the user-defined commands that you save in the Run menu (or even calls to other macros) – cannot be recorded . However, that same FAQ explains that you can trick the macro system to run non-recordable commands by manually editing the macro, as described in that second post. So you could manually create a macro that runs the File > Save then runs the dynamic menuCmdID assigned to your Run command or Plugin command, that you can find using UISpy!

        Alternatively, the NppExec plugin is designed for being a “shell scripting” language for Notepad++, allowing running various N++ commands and various filesystem commands. I have saved the following NppExec script as RunMyself, which saves the active file, changes to that file’s directory, and runs that file:

        NPP_SAVE
        cd "$(CURRENT_DIRECTORY)"
        cmd /c "$(FILE_NAME)"
        

        … and I use Shortcut Mapper to set its keyboard shortcut to F5 (and relegate the Run>Run command to Ctrl+Shift+F5, because I’d rather have the easiest shortcut be for the actions I use the most)

        You could do a similar script for the PythonScript plugin or other of the scripting plugins, but IMO, NppExec is best suited when you are trying to do just a sequence of actions that are too complex for Macros, but don’t have the logic or computational needs of a full programming language like Python.

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