Community
    • Login

    run system commands on save if certain criteria are met

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 779 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.
    • imthenachomanI
      imthenachoman
      last edited by

      I was wondering, is it possible to get Notepad++ to run some system commands if the current file’s folder meets some criteria?

      I use clasp for developing Google Apps Script code. When you have a local copy of a Google Apps Script project the folder will have a .clasp.json file in it.

      I want it so if when I save a file and the folder has this .clasp.json file then it should automatically run a system command: cmd /c "cd $(CURRENT_DIRECTORY) && clasp push".

      Is this possible? I saw NppEventExec but could not figure out how to get it to do what I am after.

      1 Reply Last reply Reply Quote 0
      • rinku singhR
        rinku singh
        last edited by

        @imthenachoman said:

        I was wondering, is it possible to get Notepad++ to run some system commands if the current file’s folder meets some criteria?

        you should use lua or python script plugin for get notification when file is being saved

        link text

        1 Reply Last reply Reply Quote 2
        • imthenachomanI
          imthenachoman
          last edited by

          I don’t know Lua but I know Python. So I could create a Python script to run a function on save that would check for the existence of a specific file in the directory and then run other system commands?

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @imthenachoman
            last edited by

            @imthenachoman

            Yes, using the Pythonscript plugin for Notepad++ :

            # -*- coding: utf-8 -*-
            
            from Npp import editor, notepad, NOTIFICATION
            
            def callback_npp_FILESAVED(args):
                for (filename, bufferID, index, view) in notepad.getFiles():
                    if bufferID == args['bufferID']:
                        # do your stuff with "filename" file here
                        break
            
            notepad.callback(callback_npp_FILESAVED, [NOTIFICATION.FILESAVED])
            
            1 Reply Last reply Reply Quote 3
            • imthenachomanI
              imthenachoman
              last edited by

              Humm. Thank you! I will give it a try.

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