-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-new-file.ahk
50 lines (42 loc) · 1.69 KB
/
create-new-file.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
; This is part of my AutoHotKey [1] script. When you are in Windows Explorer it
; allows you to press Ctrl+Alt+N and type a filename, and that file is created
; in the current directory and opened in the appropriate editor (usually
; [gVim](http://www.vim.org/) in my case, but it will use whatever program is
; associated with the file in Windows Explorer).
; This is much easier than the alternative that I have been using until now:
; Right click > New > Text file, delete default filename and extension (which
; isn't highlighted in Windows 7), type the filename, press enter twice.
; (Particularly for creating dot files like ".htaccess".)
; Credit goes to aubricus [2] who wrote most of this - I just added the
; 'IfWinActive' check and 'Run %UserInput%' at the end.
; [1]: http://www.autohotkey.com/
; [2]: https://gist.github.com/1148174
; Only run when Windows Explorer or Desktop is active
; Ctrl+Alt+N
^!n::
#IfWinActive, ahk_class ExploreWClass||ahk_class Progman||ahk_class WorkerW ||ahk_class CabinetWclass
{
; Get full path from open Explorer window
WinGetText, FullPath, A
; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")
; Change working directory
SetWorkingDir, %FullPath%
; An error occurred with the SetWorkingDir directive
If ErrorLevel {
Send, ^!n
Return
}
; Display input box for filename
InputBox, UserInput, New File (example: foo.txt), , , 400, 100
; User pressed cancel
If ErrorLevel
Return
; Create file
FileAppend, , %UserInput%
; Open the file in the appropriate editor
;Run %UserInput%
Return
}
#IfWinActive