Skip to content

Instantly share code, notes, and snippets.

@elgalu
Last active December 21, 2015 16:48
Show Gist options
  • Save elgalu/6335903 to your computer and use it in GitHub Desktop.
Save elgalu/6335903 to your computer and use it in GitHub Desktop.
Hotkey to create a new empty file in Windows Explorer {Ctrl+Alt+N} using AutoHotKey. When in Windows Explorer this allows you to press {Ctrl+Alt+N} then type a file name that will be created in the current directory. In a similar way you use {Ctrl+Shift+N} to create a new folder. Tested on Windows 8 x64 (2012); AutoHotKey 1.1.11 (2013)
;------------------------------------------------------------------------------
;begin Create a new file with Ctrl+Alt+N keyboard shortcut in Windows Explorer
;------------------------------------------------------------------------------
SetTitleMatchMode RegEx
; Ctrl+Alt+N to create new empty file
#IfWinActive ahk_class CabinetWClass ;Windows Explorer
^!n::
ExplorerFocusFilePane()
Sleep 50
Send {End}
CreateNewEmptyFile()
Sleep 50
Send {F5}
Sleep 40
Send z
Sleep 10
Send {F2}
return
#IfWinActive
ExplorerFocusFilePane()
{
ControlFocus, DirectUIHWND3, A
SendInput, {Space}
}
CreateNewEmptyFile()
{
WinGetText, current_path, A
StringSplit, w_ary, current_path, `n
Loop, %w_ary0%
{
IfInString, w_ary%A_Index%, Address
{
current_path := w_ary%A_Index%
break
}
}
current_path := RegExReplace(current_path, "^Address: ", "")
StringReplace, current_path, current_path, `r, , all
IfInString current_path, \
{
NoFile = 0
Loop
{
IfExist %current_path%\zNewEmptyFile%NoFile%
NoFile++
else
break
}
FileAppend, ,%current_path%\zNewEmptyFile%NoFile%
}
else
{
return
}
}
;------------------------------------------------------------------------------
;end Create a new file with Ctrl+Alt+N keyboard shortcut in Windows Explorer
;------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment