Skip to content

Instantly share code, notes, and snippets.

@LewkyB
Created May 23, 2020 04:23
Show Gist options
  • Save LewkyB/56cdb68ad75345d40f64a64ea5c95482 to your computer and use it in GitHub Desktop.
Save LewkyB/56cdb68ad75345d40f64a64ea5c95482 to your computer and use it in GitHub Desktop.
AHK script for RAlt + t will create a new text file in file explorer focus
; create new text file in current window focus
#IfWinActive ahk_class CabinetWClass
>!t:: ;explorer - create new text file and focus/select it
#IfWinActive ahk_class ExploreWClass
>!t:: ;explorer - create new text file and focus/select it
;note: similar to: right-click, New, Text Document
vNameNoExt := "New Text Document"
vDotExt := ".txt"
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
if (oWin.HWND = hWnd)
{
vDir := RTrim(oWin.Document.Folder.Self.Path, "\")
;if !DirExist(vDir)
if !InStr(FileExist(vDir), "D")
{
oWin := ""
return
}
Loop
{
vSfx := (A_Index=1) ? "" : " (" A_Index ")"
vName := vNameNoExt vSfx vDotExt
vPath := vDir "\" vName
if !FileExist(vPath)
break
}
;create a blank text file (ANSI/UTF-8/UTF-16)
;FileAppend,, % "*" vPath
FileAppend,, % "*" vPath, UTF-8
;FileAppend,, % "*" vPath, UTF-16
;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
Loop 30
{
if !(oWin.Document.Folder.Items.Item(vName).path = "")
{
oWin.Document.SelectItem(vPath, 0x1F)
break
}
Sleep, 100
}
break
}
}
oWin := ""
return
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment