Skip to content

Instantly share code, notes, and snippets.

@dnery
Created April 14, 2021 00:05
Show Gist options
  • Save dnery/1f0376bc6dc911e3fc6810307f0fff3c to your computer and use it in GitHub Desktop.
Save dnery/1f0376bc6dc911e3fc6810307f0fff3c to your computer and use it in GitHub Desktop.
AutoHotkey script to create a new file in the current folder
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
^!n::
IfWinActive, ahk_class CabinetWClass
current_path := GetActiveExplorerPath()
inputbox, fname, New File, Creating new file in:`n%current_path%,
fname := strreplace(fname, a_space, "")
if (fname="")
{
msgbox, No file created!
return
}
new_file_path := current_path . "\" . fname
if (FileExist(new_file_path))
{
msgbox, File already exists!
return
}
FileAppend, "", %new_file_path%
return
; Create a shortcut in C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup for startup integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment