Auto-close extracted Notepad tabs after safe extraction
Problem
After running notepad-cleanup extract, users are left with all their Notepad windows still open -- often 30+ windows with multiple tabs each. The whole point of extracting was to archive and organize that content, but the cleanup of the source windows is entirely manual: clicking through each window, closing tabs one by one, handling "save?" prompts.
Current workaround:
- Manually close each window/tab by hand
- Or
taskkill /IM notepad.exe /F which kills everything with no selectivity
Neither is good. The first is tedious with 30+ windows. The second is dangerous -- it kills ALL Notepad instances including ones you're actively using that weren't part of the extraction.
Proposed solution
Add a close command (or --close flag on extract) that programmatically closes the tabs/windows that were successfully extracted:
# After extraction, close all extracted tabs
notepad-cleanup close --last
# Or as part of the extract workflow
notepad-cleanup extract --close
# Close with confirmation per window
notepad-cleanup close --last --confirm
# Force close (skip "save?" prompts)
notepad-cleanup close --last --force
# Dry run -- show what would be closed without doing it
notepad-cleanup close --last --dry-run
Tab closure strategy
The tool should navigate each Notepad window and close tabs that match the extraction manifest:
- Read the manifest from the extraction folder to know which windows/tabs were extracted
- For each window in the manifest:
a. Connect via UIA (same as Phase 2 extraction)
b. For each tab, verify content matches the extracted file (hash comparison)
c. Close the tab using Ctrl+W or UIA close button
d. Handle the "save?" dialog: click "Don't Save" (or "Save" if --save-first)
- If a window has no remaining tabs, it closes automatically
- If content doesn't match (user edited since extraction), skip that tab and warn
Tab identification and safety
| Scenario |
Behavior |
| Tab content matches extracted file exactly |
Close the tab |
| Tab was modified since extraction |
Skip, warn user ("tab01.txt was modified since extraction") |
| Tab is a new unsaved tab not in manifest |
Skip (not ours to close) |
| Window has mix of extracted + non-extracted tabs |
Close only extracted tabs, leave others |
| "Do you want to save?" dialog appears |
Click "Don't Save" (or "Save" with --save-first) |
| Tab fails to close |
Warn and continue to next tab |
--force flag |
Close without content verification |
Implementation approach
Phase 1: Basic close command
- New
close command in cli.py
- Reads manifest from
--last or explicit folder
- Connects to each window via UIA (reuses
discovery.py patterns)
- Hashes current tab content and compares to manifest
- Closes matching tabs via
Ctrl+W keystroke
- Handles "save?" dialog via UIA button detection
Phase 2: Smart close
- Track which tabs were already linked (from
compare --link) vs genuinely new
- Option to close only linked/duplicate tabs (safe -- the canonical copy exists elsewhere)
- Integration with
run command: notepad-cleanup run --close
Key modules affected:
cli.py -- new close command
extractor.py -- reuse UIA connection patterns, add tab close logic
- Possibly new
closer.py module to keep extraction and closing separate
Design considerations
- UIA
Ctrl+W vs close button: Ctrl+W closes the active tab in Notepad. We'd need to select the tab first (already done in Phase 2), then send Ctrl+W. The "save?" dialog appears as a UIA window we can detect and dismiss
- Window handle stability: Notepad window handles stay stable during the session, and the manifest records them. But if the user closed/reopened Notepad since extraction, handles are stale. Need to fall back to content matching
- Timing: After each
Ctrl+W, need a brief delay for the UI to update before moving to the next tab. Similar to the 0.15s delay in Phase 2 extraction
- All-windows kill safety: The
--force flag should still only close windows that were in the extraction manifest, never arbitrary Notepad instances
- Unsaved content: By default, choose "Don't Save" since we already have the content extracted. The
--save-first flag would click "Save" instead for users who want to preserve to the original file location
Acceptance criteria
Related issues
Auto-close extracted Notepad tabs after safe extraction
Problem
After running
notepad-cleanup extract, users are left with all their Notepad windows still open -- often 30+ windows with multiple tabs each. The whole point of extracting was to archive and organize that content, but the cleanup of the source windows is entirely manual: clicking through each window, closing tabs one by one, handling "save?" prompts.Current workaround:
taskkill /IM notepad.exe /Fwhich kills everything with no selectivityNeither is good. The first is tedious with 30+ windows. The second is dangerous -- it kills ALL Notepad instances including ones you're actively using that weren't part of the extraction.
Proposed solution
Add a
closecommand (or--closeflag onextract) that programmatically closes the tabs/windows that were successfully extracted:Tab closure strategy
The tool should navigate each Notepad window and close tabs that match the extraction manifest:
a. Connect via UIA (same as Phase 2 extraction)
b. For each tab, verify content matches the extracted file (hash comparison)
c. Close the tab using
Ctrl+Wor UIA close buttond. Handle the "save?" dialog: click "Don't Save" (or "Save" if
--save-first)Tab identification and safety
--save-first)--forceflagImplementation approach
Phase 1: Basic close command
closecommand incli.py--lastor explicit folderdiscovery.pypatterns)Ctrl+WkeystrokePhase 2: Smart close
compare --link) vs genuinely newruncommand:notepad-cleanup run --closeKey modules affected:
cli.py-- newclosecommandextractor.py-- reuse UIA connection patterns, add tab close logiccloser.pymodule to keep extraction and closing separateDesign considerations
Ctrl+Wvs close button:Ctrl+Wcloses the active tab in Notepad. We'd need to select the tab first (already done in Phase 2), then sendCtrl+W. The "save?" dialog appears as a UIA window we can detect and dismissCtrl+W, need a brief delay for the UI to update before moving to the next tab. Similar to the 0.15s delay in Phase 2 extraction--forceflag should still only close windows that were in the extraction manifest, never arbitrary Notepad instances--save-firstflag would click "Save" instead for users who want to preserve to the original file locationAcceptance criteria
notepad-cleanup close --lastcloses tabs that match the most recent extraction--save-first)--dry-runshows which tabs would be closed without closing them--confirmprompts per window before closing--forceskips content verification--closeflag onextractruns close after successful extraction--lastand...notationRelated issues
closecould use saved paths to decide whether "Save" or "Don't Save" is appropriate