-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateFile.ahk
More file actions
133 lines (113 loc) · 3.51 KB
/
Copy pathCreateFile.ahk
File metadata and controls
133 lines (113 loc) · 3.51 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#Requires AutoHotkey v2.0
#SingleInstance Force
;; AutoHotKey script
;; https://www.autohotkey.com/
;; Description:
;; Creates a new text file and opens it in Notepad++.
;; Developer
;; Christoffel
;; https://www.fiverr.com/christoffel16
;; August 2025
;; License: GPL
CoordMode 'ToolTip', 'Screen'
global filename := ''
F1 & t:: { ;;text file
target_dir := SetTargetDir()
filename := EnterFileName(target_dir,"")
output_path := target_dir '\' filename '.txt'
if !FileExist(output_path) {
FileAppend('', output_path)
MainTooltip('File created: ' output_path)
} else {
MainTooltip('File already exists: ' output_path)
}
Run('notepad++.exe "' output_path '"')
}
F1 & m:: { ;; markdown file
target_dir := SetTargetDir()
filename := EnterFileName(target_dir,"")
output_path := target_dir '\' filename '.md'
if !FileExist(output_path) {
FileAppend('', output_path)
MainTooltip('File created: ' output_path)
} else {
MainTooltip('File already exists: ' output_path)
}
Run('Typora.exe "' output_path '"')
}
F1 & w:: { ;;Word file
target_dir := SetTargetDir()
filename := EnterFileName(target_dir,"")
output_path := target_dir '\' filename '.docx'
if !FileExist(output_path) {
FileAppend('', output_path)
MainTooltip('File created: ' output_path)
} else {
MainTooltip('File already exists: ' output_path)
}
Run('WINWORD.exe "' output_path '"')
}
F1 & p:: { ;;PowerPoint file
target_dir := SetTargetDir()
filename := EnterFileName(target_dir,"")
output_path := target_dir '\' filename '.pptx'
if !FileExist(output_path) {
FileAppend('', output_path)
MainTooltip('File created: ' output_path)
} else {
MainTooltip('File already exists: ' output_path)
}
Run('POWERPNT.exe "' output_path '"')
}
F1 & e:: { ;;Excel file
target_dir := SetTargetDir()
filename := EnterFileName(target_dir,"")
output_path := target_dir '\' filename '.xlsx'
if !FileExist(output_path) {
;;FileAppend('', output_path)
MainTooltip('File created: ' output_path)
} else {
MainTooltip('File already exists: ' output_path)
}
;;Run('EXCEL.exe "' output_path '"')
xl := ComObject("Excel.Application")
xl.Visible := true
wb := xl.Workbooks.Add() ; new workbook with one sheet
wb.SaveAs(output_path, 51)
;;wb.Close(false)
}
GetActiveExplorerPath() {
for window in ComObject("Shell.Application").Windows {
try {
if (WinActive("ahk_id " window.HWND)) {
return window.Document.Folder.Self.Path
}
}
}
return ""
}
SetTargetDir() {
if WinActive('ahk_class CabinetWClass ahk_exe explorer.exe')
target_dir := GetActiveExplorerPath()
else
target_dir := A_Desktop
return target_dir
}
EnterFileName(target_dir,filename) {
loop {
ib := InputBox('Input the name of the file to create on:`n' target_dir, 'Input filename', 'h110', filename)
if ib.Result = 'Cancel'
return MainTooltip('canceled by user')
filename := ib.Value
; Check for valid filename: not empty, no invalid chars
if filename != '' && !RegExMatch(filename, '[\\/:*?"<>|]')
break
MsgBox('Please enter a valid filename (no \ / : * ? " < > | and not empty).', 'Invalid Filename', 48)
}
return filename
}
MainTooltip(text) {
ToolTip(text)
SetTimer(() => ToolTip(), -2000)
return
}