Community discussions

MikroTik App
 
User avatar
miku
just joined
Topic Author
Posts: 15
Joined: Fri Feb 23, 2024 3:57 pm
Location: Poland

Notepad++ & RouterOS Scripts integration

Sun Mar 03, 2024 11:26 pm

Hello,
I'm newbie to this forum, but I have some experience with MikroTik devices and programming in several languages. I know that many of you use Notepad++ as the RouterOS script editor. Therefore, I am sharing a description of the my solution that allows you to download and upload the source code directly from/to the RouterOS device. Just by one click from the Run menu in the Notepad++ editor.
Everything was written and tested on Windows 10, but it should also work properly on Windows 11. If anyone has Win11, please test it.

Prerequisites:
  1. Installed Notepad++ (N++), of course :-). I used latest version 8.6.4 (64bit)
  2. Enabled RouterOS script syntax highlighting in N++. There are several threads on this forum regarding this issue. But the easiest way is to use the UDL (User Defined Language) repository, which is available in the "Language->Notepad++ User Defined Language collection" menu. Currently there is “RouterOS Script - NieL™”
  3. Active REST API on the RouterOS device.
  4. Installed jq utility. It's a small but powerful command line JSON processor. Can be downloaded for free from https://jqlang.github.io/jq/. The exe file should be placed in a directory belonging to the PATH of the Windows system or user. I used latest 1.7.1 compiled for Windows 64bit.

Installation steps:
  1. Download the ROSintegration_v1.zip file attached below and extract the contents to the directory where Notepad++ is located (notepad++.exe). Most often it is c:\Program files\Notepad++. The ZIP archive contains 3 files:
    1. ROSlib.cmd – utility functions for other two scripts
    2. ROSdownload.cmd - script that downloads code from the RouterOS device into the N++ document
    3. ROSupload.cmd - script that uploads code from the N++ document into the RouterOS device
  2. Open to edit (using N++) file ROSlib.cmd, find line contains set jqBinary=jq-windows-amd64.exe and change it value to name or path to your jq executable file
    :getJqBinary RtnVar
        rem Name or full path to jq utility executable
        rem see https://jqlang.github.io/jq/
        set jqBinary=jq-windows-amd64.exe
        set "%~1=%jqBinary%"
        exit /B
    
  3. Open to edit (using N++) file shortcuts.xml, located in the same directory as the notepad++.exe file. Create backup copy of this file before…
  4. Paste the code below between the tags <UserDefinedCommands> </UserDefinedCommands> of the shortcuts.xml. You must replace url_to_your_router_os_api and api_username:user_password with your own values. If you want, modify the "name" attribute.
    <Command name="Download RouterOS script" Ctrl="no" Alt="yes" Shift="no" Key="34">
    "$(NPP_DIRECTORY)\ROSdownload.cmd" "url_to_your_router_os_api" "api_username:user_password" "$(FULL_CURRENT_PATH)"
    </Command>
    <Command name="Upload RouterOS script" Ctrl="no" Alt="yes" Shift="no" Key="33">
    "$(NPP_DIRECTORY)\ROSupload.cmd" "url_to_your_router_os_ap" "api_username:user_password" "$(FULL_CURRENT_PATH)"
    </Command>
    
  5. Save shortcuts.xml file and restart Notepad++
  6. You should now see the new commands in the Run N++ menu
    ROSintegration.png
Usage:
  1. In Notepad++, create a new document whose name will be identical to the name of the script in the RouterOS device. For example, if the name of the script on the router is wanFailover, name the new document wanFailover.rsc
  2. Run command “Run->Download RouterOS script” or press Alt+Page Down. You should see source code inside document.
  3. Make any changes in Notepad++ document. For example add new comment. Save document and “Run->Upload RouterOS script” or press Alt+Page Up
  4. Open WinBox and check source code of your script. You should see modifications made in Notepad++.

You can change everything, but please keep the CC BY license information contained in the ROS*.cmd files- and remember, this is a version beta, tested and used only be me so far...

Notepad++ & RouterOS Scripts integration © 2024 by miku (forum.mikrotik.com) is licensed under CC BY
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: malks and 9 guests