-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathclipboard.ahk
120 lines (99 loc) · 3.33 KB
/
clipboard.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
; Clipboard-related functions.
copyWithHotkey(hotkeyKeys) {
if(hotkeyKeys = "")
return
clipboard := "" ; Clear the clipboard so we can wait for it to actually be set
Send, % hotkeyKeys
ClipWait, 0.5 ; Wait for the minimum time (0.5 seconds) for the clipboard to contain the new info.
}
copyFilePathWithHotkey(hotkeyKeys) {
copyWithHotkey(hotkeyKeys)
path := clipboard
if(path) {
path := cleanupPath(path)
path := mapPath(path)
}
setClipboardAndToastValue(path, "file path")
}
copyFolderPathWithHotkey(hotkeyKeys) {
copyWithHotkey(hotkeyKeys)
path := clipboard
if(path) {
path := cleanupPath(path)
path := mapPath(path)
path := appendCharIfMissing(path, "\") ; Add the trailing backslash since it's a folder
}
setClipboardAndToastValue(path, "folder path")
}
;---------
; DESCRIPTION: Add something to the clipboard history, restoring the original clipboard value.
; PARAMETERS:
; textToSave (I,REQ) - Text to add to the clipboard history.
;---------
addToClipboardHistory(textToSave) {
originalClipboard := clipboardAll
clipboard := textToSave
saveCurrentClipboard()
clipboard := originalClipboard
saveCurrentClipboard()
}
;---------
; DESCRIPTION: Force the clipboard manager to store the current value, generally useful just
; before you change the clipboard to something else.
;---------
saveCurrentClipboard() {
; If the ditto function is available that's preferable (no wait time), but fall back if needed.
functionName := "dittoSaveCurrentClipboard" ; dittoSaveCurrentClipboard()
if(isFunc(functionName))
%functionName%()
else
Sleep, 1000
}
; Sends the selected text using the clipboard, fixing the clipboard as it finishes.
sendTextWithClipboard(text) {
; DEBUG.popup("Text to send with clipboard", text)
originalClipboard := clipboardAll ; Save off the entire clipboard.
clipboard := "" ; Clear the clipboard
clipboard := text
ClipWait, 0.5 ; Wait for clipboard to contain the data we put in it (minimum time).
Send, ^v
Sleep, 100
clipboard := originalClipboard ; Restore the original clipboard. Note we're using clipboard (not clipboardAll).
}
setClipboard(value) {
clipboard := "" ; Clear the clipboard so we can wait for it to actually be set
clipboard := value
ClipWait, 2 ; Wait for 2 seconds for the clipboard to contain data.
}
setClipboardAndToastState(newClipboardValue, clipLabel := "value") {
setClipboard(newClipboardValue)
toastNewClipboardState(clipLabel)
}
setClipboardAndToastValue(newClipboardValue, clipLabel := "value") {
setClipboard(newClipboardValue)
toastNewClipboardValue(clipLabel)
}
setClipboardAndToastError(newClipboardValue, clipLabel, problemMessage, errorMessage := "") {
if(clipLabel = "")
clipLabel := "value"
setClipboard(newClipboardValue)
Toast.showError(problemMessage, errorMessage, "Clipboard set to " clipLabel ":`n" clipboard)
}
toastNewClipboardState(clipLabel := "value") {
toastClipboard(clipLabel, false)
}
toastNewClipboardValue(clipLabel := "value") {
toastClipboard(clipLabel, true)
}
toastClipboard(clipLabel, showClipboardValue) {
if(clipLabel = "")
clipLabel := "value"
if(clipboard = "") {
Toast.showError("Failed to get " clipLabel)
} else {
clipMessage := "Clipboard set to " clipLabel
if(showClipboardValue)
clipMessage .= ":`n" clipboard
Toast.showMedium(clipMessage)
}
}