Skip to content

Instantly share code, notes, and snippets.

@aubricus
Created August 16, 2011 00:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aubricus/1148174 to your computer and use it in GitHub Desktop.
Save aubricus/1148174 to your computer and use it in GitHub Desktop.
AutoHotkey script to create a new file.
; create new file
; installation:
; 1. you must be running autohotkey: http://www.autohotkey.com
; 2. double click on script to run
; [pro-tip] add this script to your startup folder to run when windows start
; [pro-top] you can add this script to another .ahk script file.
; hotkey is set to control + alt + n
; more on hotkeys: http://www.autohotkey.com/docs/Hotkeys.htm
^!n::
; script will automatically use its current directory as its "working directory"
; to get the file to appear in the active directory we have to extract
; the full path from the window(stupid!)
; get full path from open windows
WinGetText, FullPath, A
; split up result (returns paths seperated by newlines [also lame])
StringSplit, PathArray, FullPath, `n
; get first item
FullPath = %PathArray1%
; clean up result
FullPath := RegExReplace(FullPath, "(^Address: )", "")
StringReplace, FullPath, FullPath, `r, , all
; change working directory
SetWorkingDir, %FullPath%
; an error occurred with the SetWorkingDir directive
if ErrorLevel
return
; display input box for file name
InputBox, UserInput, New File (example: foo.txt), , ,400, 100
; user pressed cancel
if ErrorLevel
return
; success! output file with user input
else
FileAppend, ,%UserInput%
return
@d13r
Copy link

d13r commented Mar 3, 2012

Thanks, this is really useful.

I also added Run %UserInput% to the end, to load the file in the appropriate editor.

Also #IfWinActive ahk_class CabinetWClass before it, so it only tries to run when Explorer is active.

@aubricus
Copy link
Author

aubricus commented Mar 9, 2012

Dave, Glad you found some use out of it! Would you mind posting a link to your version of it? Thanks!

@d13r
Copy link

d13r commented Mar 9, 2012

Sure, I created it as a fork: https://gist.github.com/1965432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment