how to close all tabs in notepad windows 11

install Python in your system save it as [ closer.py ] - @Zsezt
mail@pastecode.io avatar
unknown
python
a month ago
972 B
3
Indexable
Never
import pyautogui
import subprocess
import time

def close_all_notepad_tabs():
    # Display status messages in the terminal
    print("Closing all tabs.....")
    print("tool by @Zsezt")

    # Open Notepad if it's not running
    subprocess.Popen(['notepad.exe'])
    time.sleep(1)  # Wait for Notepad to open

    # Activate the Notepad window (brings it into focus)
    pyautogui.hotkey('alt', 'tab')

    # Run an infinite loop to continuously close tabs
    while True:
        pyautogui.hotkey('ctrl', 'w')  # Close the current tab
        time.sleep(0.2)  # Shorter pause for quicker operation
        
        # Use arrow keys to navigate to "Don't Save" (press Right arrow, then Enter)
        pyautogui.press('right')  # Move focus to "Don't Save"
        pyautogui.press('enter')  # Confirm by pressing Enter
        time.sleep(0.2)  # Short pause before closing the next tab

if __name__ == "__main__":
    close_all_notepad_tabs()
Leave a Comment