Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@davejamesmiller

This comment has been minimized.

Copy link

@davejamesmiller davejamesmiller 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

This comment has been minimized.

Copy link
Owner Author

@aubricus 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!

@davejamesmiller

This comment has been minimized.

Copy link

@davejamesmiller davejamesmiller 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