-
Notifications
You must be signed in to change notification settings - Fork 3
/
WTF.ahk
287 lines (217 loc) · 5.5 KB
/
WTF.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
File: "WTF.ahk"
Author: Rob Lund
Site: http://www.electrolund.com/2015/11/the-lack-of-file-tags-in-windows/
License: freely distributable
Description:
Windows Tags for Files (WTF)
Applies "tags" by renaming selected files in Explorer.
compatible up to Windows 10, except for desktop mode
Tags are mutually exclusive, i.e., you can't have multiple tags on one file.
Notes:
Shortcut key is bound
Avoid these illegal NTFS characters for tag name tokens
\ / : * ? " < > |
Icon created with Paint.net. Photoshop compatible design file included.
References:
Uses the following Explorer AHK library...
http://autohotkey.com/board/topic/60985-get-paths-of-selected-items-in-an-explorer-window/
Notes:
*/
/********************
Initialization
*/
#SingleInstance force
#include explorer window info.ahk
script_version := 2.0
global script_debug := FALSE
global script_warn := FALSE
script_title = Windows Tags for Files
script_title_short = WTF ; acroynms make the world go round
; compiled version has custom tray icon and menus
if A_IsCompiled
{
Menu, Tray, Icon, %A_ScriptFullPath%, -159
Menu, Tray, Tip, %script_title%
Menu, Tray, NoStandard
Menu, Tray, Add, Edit Preferences, MenuEdit
Menu, Tray, Disable, Edit Preferences
Menu, Tray, Add, Warn Before Tagging?, MenuWarning
Menu, Tray, Add, Debug Mode, MenuDebug
Menu, Tray, Add, ; separater line
Menu, Tray, Add, Exit, QuitScriptSub
}
; Tagging setup
tagToken = @
tag1Name = done
tag2Name = TODO
tagNone = none
; Generated using SmartGUI Creator 4.0
Gui, Add, Button, x22 y60 w80 h30 , &Todo
Gui, Add, Button, x132 y60 w80 h30 , &Done
Gui, Font, s14, Verdana
Gui, Add, Text, x20 y10, %script_title%
Gui, Font, S10 CDefault, Verdana
Gui, Font, S10 CDefault Bold, Verdana
Gui, Add, Button, x132 y140 w80 h30 , &Quit
Gui, Font, S8 CDefault, Verdana
Gui, Add, Button, x22 y140 w80 h30 , &Delete
Return
/******************
All tags GUI
Win + F1
*/
#F1::
; look up selected files
Gosub, GetFiles
; proceed only if there were files
if fileCount > 0
{
Gui, Show, x127 y87 h205 w239, %script_title_short%
}
Return
/****************************
TODO hotkey or GUI button
Win + t
*/
#t::
; look up selected files
Gosub, GetFiles
ButtonTodo: ; label order is vital!
; now tag them
Tagger(tag2Name)
Gui, Cancel
Return
/****************************
Done hotkey or GUI button
Win + d
*/
#d::
; look up selected files
Gosub, GetFiles
ButtonDone: ; label order is vital!
; now tag them
Tagger(tag1Name)
Gui, Cancel
Return
/*********************
Delete GUI button
*/
ButtonDelete:
Tagger(tagNone)
Gui, Cancel
Return
/*********************
Quit GUI button
*/
ButtonQuit:
Gui, Cancel
Return
/****************************
GetFiles subroutine
looks for selected files
returns TRUE/FALSE status
*/
GetFiles:
; initialize
global fileCount = 0
; look up the selected files
selectedFiles := Explorer_GetSelected()
; error check
if (selectedFiles = "ERROR")
{
MsgBox, 16, %script_title_short% Error, Windows Explorer is not in focus!
}
else if (selectedFiles = "")
{
MsgBox, 48, %script_title%, Windows Explorer is open and in focus, but no files are selected.
}
else
{
; parse the selected file paths, terminating on line feeds
Loop, Parse, selectedFiles, `n, `r
{
path := A_LoopField
; split the path into its constituent parts in pseudo-arrays
SplitPath, path, fullname%A_Index%, directory%A_Index%, extension%A_Index%, name%A_Index%
if script_debug
MsgBox, 64, (DEBUG) File #%A_Index% Parts, % "Full filename = " fullname%A_Index% "`nDirectory = " directory%A_Index% "`nExtension = " extension%A_Index% "`nName only = " name%A_Index%
fileCount = %A_Index%
}
}
Return
/****************************
Tagger Function
tags the selected files
with input tag type
*/
Tagger(tagType)
{
; assume all variables used here are global
global
Loop, %fileCount%
{
; strip out any previous tags first, regardless of called tag
IfInString, name%A_Index%, %tagToken%%tag1Name%
{
StringTrimRight, newName, name%A_Index%, StrLen(tagToken . tag1Name) + 1
}
Else IfInString, name%A_Index%, %tagToken%%tag2Name%
{
StringTrimRight, newName, name%A_Index%, StrLen(tagToken . tag2Name) + 1
}
Else
{
; file isn't tagged, use as is
newName := name%A_Index%
}
; build old and new full file paths
oldPath := directory%A_Index% . "\" . name%A_Index% . "." . extension%A_Index%
if (tagType = tagNone)
newPath := directory%A_Index% . "\" . newName . "." . extension%A_Index%
else
newPath := directory%A_Index% . "\" . newName . " " . tagToken . tagType . "." . extension%A_Index%
if script_debug
{
MsgBox, 64, (DEBUG) Old Name, %oldPath%
MsgBox, 64, (DEBUG) New Name, %newPath%
}
; warn before renaming
if script_warn
MsgBox, 0x24, %script_title_short%, About to rename files. Proceed?
IfMsgBox No
Return
; now rename
FileMove, %oldPath%, %newPath%
; error check
if ErrorLevel <> 0
MsgBox, 16, %script_title_short% Error, %ErrorLevel% files/folders could not be tagged.
}
}
/**********************
Script preferences
*/
MenuEdit:
if script_debug
MsgBox You selected %A_ThisMenuItem% from menu %A_ThisMenu%.
Return
MenuDebug:
Menu, Tray, ToggleCheck, Debug Mode
if script_debug
script_debug := FALSE
else
script_debug := TRUE
Return
MenuWarning:
Menu, Tray, ToggleCheck, Warn Before Tagging?
if script_warn
script_warn := FALSE
else
script_warn := TRUE
Return
/**********************
Shut down script
*/
QuitScriptSub:
GuiClose:
ExitApp ; Terminate this script