最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Notepad++ renaming tabs with python scripts - Stack Overflow

programmeradmin10浏览0评论

I want to rename my current tab to something other than "New1" but not save This is so that when i open a tab with my script, the tab would have a better describing name. I work with log files and open parts of log with formatting scripts.

I can rename tab in notepad++ by right clicking tab and rename.

Is there a possibility to do the same with python scripts something like notepad.setTabTitle("My_new_name")

My quite simple script looks like this: selects the line cursor is at, copies it and pastes the copied line to a new tab, formats that text

myline = editor.getCurLine()
editor.copyText(myline)
notepad.new() #rename here or after this line
editor.paste()
editor.selectAll()
notepad.runPluginCommand("MIME Tools", "Base64 decode")
notepad.runPluginCommand("XML Tools", "Pretty print")

I want to rename my current tab to something other than "New1" but not save This is so that when i open a tab with my script, the tab would have a better describing name. I work with log files and open parts of log with formatting scripts.

I can rename tab in notepad++ by right clicking tab and rename.

Is there a possibility to do the same with python scripts something like notepad.setTabTitle("My_new_name")

My quite simple script looks like this: selects the line cursor is at, copies it and pastes the copied line to a new tab, formats that text

myline = editor.getCurLine()
editor.copyText(myline)
notepad.new() #rename here or after this line
editor.paste()
editor.selectAll()
notepad.runPluginCommand("MIME Tools", "Base64 decode")
notepad.runPluginCommand("XML Tools", "Pretty print")
Share Improve this question edited Mar 27 at 8:00 user20477151 asked Mar 27 at 7:50 user20477151user20477151 11 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 0

The following python code will use notepad++ to open an existing file in the current folder and make the tab name equal to the name of the file opened:

import os
import subprocess

notepad_plus_plus = r"C:\Program Files\Notepad++\notepad++.exe"
file_name = "test.txt"

if os.path.exists(file_name):
    subprocess.run([notepad_plus_plus, file_name])
else:
    print("File not found")
发布评论

评论列表(0)

  1. 暂无评论