Community
    • Login

    Python Script macros: Apparently I am too stupid ...

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 8.9k 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.
    • Matt IsaacsonM
      Matt Isaacson
      last edited by

      … to get the most rudimentary Python Script macro to run. I’m trying to follow the basic examples in the Introduction chapter of PythonScript.chm, which is installed with Notepad++ - in this case, app version 6.8.8, but the results are the same as I had with an earlier version a year or two ago when I tried the same thing: namely, nothing whatsoever happens.

      I have to assume that there’s some very basic detail that I haven’t picked up on - one that’s so basic, that the documentation writer(s) found it too obvious to be worth mentioning.

      Here are the steps I tried:

      Installed PythonScript.
      
      Plugins -> Python Script -> New Script
      
      Entered a file name ("LetsTryAgain") and clicked Save
      
      In the editor pane for the new file, entered text copied directly from the documentation:
      
      editor.replace("old", "new")
      
      Saved the modified file
      
      Plugins -> Python Script -> Scripts -> LetsTryAgain
      

      At this point I’d expect the macro to run - if it did, it was with no effect.
      I then replaced the content of LetsTryAgain.py with the following:

      text = "abc"
      editor.addText(text)
      

      and again tried

      Plugins -> Python Script -> Scripts -> LetsTryAgain
      

      again with no visible effect.

      Then I tried going into

      Plugins -> Python Script -> Configuration
      

      and adding LetsTryAgain.py to the Menu. I then tried going into

      Plugins -> Python Script -> LetsTryAgain
      

      since it now appears in the Python Script menu. This time it had an effect: the Python Script Configuration dialog opened.

      WTF??!? This can’t really be that hard. What am I missing here? Does anyone out there have the patience to help a seeming imbecile get to square one?

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Matt Isaacson
        last edited by

        Hello Matt-Isaacson,

        I don’t see any obvious error but could you do me a favour and open the python console?
        Plugins->Python Script->Show Console.
        Which version is displayed?
        If you run the script again, does something appear in the console?

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Matt IsaacsonM
          Matt Isaacson
          last edited by

          Hi Claudia,

          I don’t see a version display when I open the console, and when I run the macro, nothing appears in the console. If I type “LetsTryAgain” into the field at the bottom of the console and click “Run”:

          ">>> LetsTryAgain"
          

          appears in the console (without the quotes), but that’s all.

          I didn’t mention earlier that I have no Python knowledge whatsoever - but I don’t think that’s the problem here. Maybe you can walk me through a basic macro exercise that’s working on your system?

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @Matt Isaacson
            last edited by Claudia Frank

            Hello Matt,

            you already have a working example

            editor.replace("old", "new")
            

            when running the script while having the script still open in editor,
            it would replace the old by new, so results in

            editor.replace("new", "new").
            

            That you don’t see a version number makes me believe that something failed during python script installation.
            Normally you see a message like

            Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]
            Initialisation took 967ms
            Ready.
            

            Did you install the plugin by using the plugin manager or by using the .msi package from the website? Maybe give the msi a try?

            Don’t you get an error message when starting notepad++?

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • Matt IsaacsonM
              Matt Isaacson
              last edited by

              Hi Claudia,

              Thanks!! You nailed it. I installed Python Script again, from the .msi package this time instead of via the plugin manager, and now my bonehead example script works as expected, and there is a sign-on message in the console.

              How exciting!

              In answer to your other question: no, previously I wasn’t getting any error messages upon notepad++ startup. That would have been nice, of course. So is there a bug to be reported here, and if so, to whom should it be reported? Is it a plugin bug or a notepad++ bug, or both?

              Anyway, stay tuned, I’m sure I’ll have some Python Script newbie questions soon!

              Matt

              Claudia FrankC 1 Reply Last reply Reply Quote 0
              • Claudia FrankC
                Claudia Frank @Matt Isaacson
                last edited by Claudia Frank

                Hi Matt

                In answer to your other question: no, previously I wasn’t getting any error messages upon notepad++ startup. That would have been nice, of course. So is there a bug to be reported here, and if so, to whom should it be reported? Is it a plugin bug or a notepad++ bug, or both?

                That’s a good question, I assume it is the plugin manager and has to do with permissions when npp was installed instead of unpacked but didn’t tested it really.

                Anyway, stay tuned, I’m sure I’ll have some Python Script newbie questions soon!

                ;-)

                Cheers
                Claudia

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