#Requires AutoHotkey v2.0 #SingleInstance Force SetTitleMatchMode 2 ; ===================================================================== ; Prompt editor for Notepad++ - by Konversaitional (konversaitional.com) ; Write long prompts in Notepad++, paste them back into any text box. ; ; Ctrl+Alt+E in any text box (Claude, ChatGPT, ...) -> open Notepad++ ; Ctrl+Enter in that Notepad++ window -> paste back + close ; Ctrl+Alt+Q in that Notepad++ window -> cancel + close ; ; Free to use and adapt. Run only one of these scripts at a time. ; ===================================================================== ; ----- Settings ------------------------------------------------------ NPP := "C:\Program Files\Notepad++\notepad++.exe" GRAB_EXISTING := true ; true = take the text already in the box along ; and replace it when pasting back ; false = always start with an empty document TRIGGER := "^!e" ; Ctrl+Alt+E ; --------------------------------------------------------------------- global targetHwnd := 0, editorTitle := "", tmpFile := "" EXE := "notepad++.exe" Hotkey TRIGGER, OpenEditor OpenEditor(*) { global targetHwnd, editorTitle, tmpFile if editorTitle && WinExist(editorTitle " ahk_exe " EXE) { ; already open WinActivate return } if tmpFile && FileExist(tmpFile) ; leftover try FileDelete tmpFile targetHwnd := WinExist("A") text := GRAB_EXISTING ? GrabText() : "" editorTitle := "prompt_" A_Now ".md" tmpFile := A_Temp "\" editorTitle f := FileOpen(tmpFile, "w", "UTF-8-RAW"), f.Write(text), f.Close() ; Separate instance, no session -> never touches your other Notepad++ windows Run '"' NPP '" -multiInst -nosession -notabbar "' tmpFile '"' if WinWait(editorTitle " ahk_exe " EXE, , 10) { WinActivate Send "^{End}" } } #HotIf editorTitle && WinActive(editorTitle " ahk_exe " EXE) ^Enter:: Finish(true) ^!q:: Finish(false) #HotIf Finish(paste) { global editorTitle, tmpFile Send "^s" ; saved -> no "save?" prompt Sleep 250 WinClose editorTitle " ahk_exe " EXE WinWaitClose editorTitle " ahk_exe " EXE, , 5 editorTitle := "" text := FileExist(tmpFile) ? FileRead(tmpFile, "UTF-8") : "" try FileDelete tmpFile if paste PasteBack(text) } ; ----- Shared helpers ------------------------------------------------ GrabText() { saved := ClipboardAll() A_Clipboard := "" Send "^a^c" text := ClipWait(0.4) ? A_Clipboard : "" A_Clipboard := saved return text } PasteBack(text) { if !WinExist("ahk_id " targetHwnd) return WinActivate "ahk_id " targetHwnd WinWaitActive "ahk_id " targetHwnd, , 2 Sleep 100 saved := ClipboardAll() A_Clipboard := RTrim(text, "`r`n") if ClipWait(1) Send GRAB_EXISTING ? "^a^v" : "^v" Sleep 300 A_Clipboard := saved ; restore your clipboard }