├── README.md └── CreateFileMacro.ahk /README.md: -------------------------------------------------------------------------------- 1 | # CreateNewFileMacro 2 | 3 | ## How to use 4 | Pressing `Ctrl+Shift+N` creates a new blank file in the current explorer window. You can directly enter your file name + extension and hit enter. There won't be any prompts. 5 | 6 | ## Classic vs CreateNewFileMacro 7 | Creating a file in Windows can take unnecessarely long. Especially if you want to use a special file extension. 8 | The classic process would be `Right click` -> `Click "New"` -> `Click "Text file"` -> `Delete the default name "New Textfile.txt` -> `Write a new name e.g. "test.file"` -> `Press enter` -> `Now a dialog pops up aksing you if you really want to save it as .test instead of .txt and you have to click yes`. 9 | 10 | It really is an unnecessary long process. You could of course hack your registry and add new entries for more file extensions. But do you really want to bloat your context menu with all file extensions that you might ever need? I mean once the list would reach a certain length, it would take you even more time, just to find the right entry. 11 | 12 | Anway... This script tries to act as a shell extension, providing a new keyboard shortcut to create a new file MUCH faster. 13 | -------------------------------------------------------------------------------- /CreateFileMacro.ahk: -------------------------------------------------------------------------------- 1 | Menu, Tray, Icon, Imageres.dll, 3 ; new file icon 2 | TrayTip, CreateFileMacro, Ctrl+Shift+M to create a new file in the current explorer window 3 | #If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW") 4 | ^+m::CurrentWindowNewFile() ;Ctrl+Shift+M Create new, empty, entensionless file in the active explorer window or on the desktop 5 | #If 6 | 7 | CurrentWindowNewFile() { 8 | shellWindows := ComObjCreate("Shell.Application").Windows 9 | If (WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW")) { 10 | VarSetCapacity(_hwnd, 4, 0) 11 | explorerWin := shellWindows.FindWindowSW(0, "", 8, ComObj(0x4003, &_hwnd), 1) 12 | } Else { 13 | hwndActive := HexToDecimal(WinExist()) 14 | Loop % shellWindows.Count+1 { ; +1? 15 | explorerWin := shellWindows.Item(A_Index-1) 16 | If (hwndActive = explorerWin.Hwnd) 17 | Break 18 | } 19 | } 20 | sfv := explorerWin.Document 21 | items := sfv.SelectedItems 22 | Loop % items.Count 23 | sfv.SelectItem(items.Item(A_Index-1), 0) 24 | newFileName := "New File" 25 | If FileExist(sfv.Folder.Self.Path "\" newFileName) { 26 | Loop { 27 | newFileName := "New File (" A_Index+1 ")" 28 | If !FileExist(sfv.Folder.Self.Path "\" newFileName) 29 | Break 30 | } 31 | } 32 | FileAppend,, % sfv.Folder.Self.Path "\" newFileName 33 | explorerWin.Refresh() 34 | sfv.SelectItem(items.Item(newFileName), 1) 35 | Loop, 5 { ; Loop usually isn't necessary, but adds a bit of reliability. 36 | Sleep, 50 37 | Send {F2} 38 | ; Verify we're now in rename mode. 39 | ControlGetFocus focus 40 | } until (focus = "Edit1") 41 | } 42 | 43 | HexToDecimal(str){ 44 | static _0:=0,_1:=1,_2:=2,_3:=3,_4:=4,_5:=5,_6:=6,_7:=7,_8:=8,_9:=9,_a:=10,_b:=11,_c:=12,_d:=13,_e:=14,_f:=15 45 | str:=ltrim(str,"0x `t`n`r"), len := StrLen(str), ret:=0 46 | Loop,Parse,str 47 | ret += _%A_LoopField%*(16**(len-A_Index)) 48 | return ret 49 | } 50 | --------------------------------------------------------------------------------