3

I am using Notepad++ for creating scripts and opening my active files from menu "Run" -> "Open current dir cmd". This works fine and the result is:

c:\scripts>

What I would like to have is the filename that I am working on currently so that I could try testing it right away. In my scripts I use parameters to define input and output files. Therefore the script shouldn't be run while opening, rather to have the script typed into console:

c:\scripts>edit_text.pl

I would then add manually the needed input and output files

c:\scripts>edit_text.pl input.txt output.txt

How do I make this possible in Notepad++ "Run" -feature?

Currently it is defined in shortcuts.xml as

cmd /K cd $(CURRENT_DIRECTORY)

I suspect that it would be something like this:

cmd /K cd $(CURRENT_DIRECTORY) $(FILE_NAME)

The problem is that this will "execute" the filename as well. I would like to have it waiting on the console for my actions.

Thanks in advance!

1 Answer 1

1

The final code line would mean the CD and the script invocation being treated as one command. Separating then with && should help.

cmd /K cd $(CURRENT_DIRECTORY) && $(FILE_NAME)

However, that would do the CD then execute the command. I do not know of any way to enter a command but not execute it.

A poor solution would use the command below. You could copy and paste the echoed command then add in any parameters needed. Setting "Quick edit" mode on the window would make the copy and paste quicker.

cmd /K cd $(CURRENT_DIRECTORY) && ECHO $(FILE_NAME)

I have adopted a different approach for my own scripts although they do not have parameters that I need to enter. Edit the file (but not with Notepad++ as it overwrites the file just before it exits):

C:\Users\AdrianHHH\AppData\Roaming\Notepad++\shortcuts.xml

I have added some lines to the <UserDefinedCommands> section:

<NotepadPlus>
    ... unchanged
    <UserDefinedCommands>
        ... unchanged
        <Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
        <Command name="Open current dir cmd" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K cd /d $(CURRENT_DIRECTORY)</Command>
        <Command name="Run as command" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /C &quot;cd /d $(CURRENT_DIRECTORY) &amp;&amp; $(FULL_CURRENT_PATH)&quot;</Command>
        <Command name="Explorer with selection" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_WORD)</Command>
    </UserDefinedCommands>
    ... unchanged
</NotepadPlus>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer! ECHO was one thing that I tried as well but as you said it's quite poor. I'll see if I could somehow have the filename pushed to clipboard within the same function.
to send text to the clipboard you can use echo something |clip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.