forked from EposVox/WindowsMods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstantExplorer.ahk
176 lines (155 loc) · 7.66 KB
/
InstantExplorer.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
;via Taran 2nd Keyboard https://github.com/TaranVH/2nd-keyboard/blob/master/Almost%20All%20Windows%20Functions.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#WinActivateForce
global savedCLASS = "ahk_class Notepad++"
global savedEXE = "notepad++.exe"
;%A_ScriptDir%\Lib\ ; Local library - requires v1.0.90+.
;%A_MyDocuments%\AutoHotkey\Lib\ ; User library.
;path-to-the-currently-running-AutoHotkey.exe\Lib\ ; Standard library.
;C:\Users\TaranVanHemert\AppData\Local\GitHub\TutorialRepository_a66c3719071da6d865a984bb8d6bfb5bcd775ec8\new-repo\Taran's Windows Mods\WINDOWS MOD - Various functions.ahk\Lib\
Menu, Tray, Icon, shell32.dll, 16 ;this changes the icon into a little laptop thingy. just useful for making it distinct from the others.
GroupAdd, ExplorerGroup, ahk_class #32770 ;This is for all the Explorer-based "save" and "load" boxes, from any program!
;BEGIN savage-folder-navigation CODE!
;I got MOST of this code from https://autohotkey.com/docs/scripts/FavoriteFolders.htm
;and modified it to work with any given keypress, rather than middle mouse click as it had before.
InstantExplorer(f_path,pleasePrepend := 0)
{
send {SC0E8} ;scan code of an unassigned key. This is needed to prevent the item from merely FLASHING on the task bar, rather than opening the folder. Don't ask me why, but this works.
if pleasePrepend = 1
{
FileRead, SavedExplorerAddress, C:\Users\TaranWORK\Documents\GitHub\2nd-keyboard\Taran's Windows Mods\SavedExplorerAddress.txt
;msgbox, current f_path is %f_path%
f_path = %SavedExplorerAddress%\%f_path% ;no need to use . to concatenate
;msgbox, new f_path is %f_path%
}
;for Keyshower, put code here to find the first / and remove the string before it. otherwise you can't see the final folder name
;Keyshower(f_path,"InstExplor")
if IsFunc("Keyshower") {
Func := Func("Keyshower")
RetVal := Func.Call(f_path,"InstExplor")
}
f_path := """" . f_path . """" ;this adds quotation marks around everything so that it works as a string, not a variable.
;msgbox, f_path is now finally %f_path%
;SoundBeep, 900, 400
; These first few variables are set here and used by f_OpenFavorite:
WinGet, f_window_id, ID, A
WinGetClass, f_class, ahk_id %f_window_id%
WinGetTitle, f_title, ahk_id %f_window_id% ;to be used later to see if this is the export dialouge window in Premiere...
if f_class in #32770,ExploreWClass,CabinetWClass ; if the window class is a save/load dialog, or an Explorer window of either kind.
ControlGetPos, f_Edit1Pos, f_Edit1PosY,,, Edit1, ahk_id %f_window_id%
/*
if f_AlwaysShowMenu = n ; The menu should be shown only selectively.
{
if f_class in #32770,ExploreWClass,CabinetWClass ; Dialog or Explorer.
{
if f_Edit1Pos = ; The control doesn't exist, so don't display the menu
return
}
else if f_class <> ConsoleWindowClass
return ; Since it's some other window type, don't display menu.
}
; Otherwise, the menu should be presented for this type of window:
;Menu, Favorites, show
*/
; msgbox, A_ThisMenuItemPos %A_ThisMenuItemPos%
; msgbox, A_ThisMenuItem %A_ThisMenuItem%
; msgbox, A_ThisMenu %A_ThisMenu%
;;StringTrimLeft, f_path, f_path%A_ThisMenuItemPos%, 0
; msgbox, f_path: %f_path%`n f_class: %f_class%`n f_Edit1Pos: %f_Edit1Pos%
; f_OpenFavorite:
;msgbox, BEFORE:`n f_path: %f_path%`n f_class: %f_class%`n f_Edit1Pos: %f_Edit1Pos%
; Fetch the array element that corresponds to the selected menu item:
;;StringTrimLeft, f_path, f_path%A_ThisMenuItemPos%, 0
if f_path =
return
if f_class = #32770 ; It's a dialog.
{
;msgbox, f_title is %f_title%
if f_title = Export Settings
{
;msgbox,,,you are in Premiere's export box. no bueno.,0.7
GOTO, ending2
;return ;I don't want to return because i still want to open an explorer window.
}
if f_Edit1Pos <> ; And it has an Edit1 control.
{
; IF window Title is NOT "export settings," with the exe "premiere pro.exe"
;go to the end or do something else, since you are in Premiere's export media dialouge box... which has the same #23770 classNN for some reason...
ControlFocus, Edit1, ahk_id %f_window_id% ;this is really important.... it doesn't work if you don't do this...
;tippy2("DIALOUGE WITH EDIT1`n`nLE controlfocus of edit1 for f_window_id was just engaged.", 1000)
; msgbox, is it in focus?
; MouseMove, f_Edit1Pos, f_Edit1PosY, 0
; sleep 10
; click
; sleep 10
; msgbox, how about now? x%f_Edit1Pos% y%f_Edit1PosY%
;msgbox, edit1 has been clicked maybe
; Activate the window so that if the user is middle-clicking
; outside the dialog, subsequent clicks will also work:
WinActivate ahk_id %f_window_id%
; Retrieve any filename that might already be in the field so
; that it can be restored after the switch to the new folder:
ControlGetText, f_text, Edit1, ahk_id %f_window_id%
ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
Sleep, 100 ; It needs extra time on some dialogs or in some cases.
ControlSetText, Edit1, %f_text%, ahk_id %f_window_id%
;msgbox, AFTER:`n f_path: %f_path%`n f_class: %f_class%`n f_Edit1Pos: %f_Edit1Pos%
return
}
; else fall through to the bottom of the subroutine to take standard action.
}
;for some reason, the following code just doesn't work well at all.
/*
else if f_class in ExploreWClass,CabinetWClass ; In Explorer, switch folders.
{
tooltip, f_class is %f_class% and f_window_ID is %f_window_id%
if f_Edit1Pos <> ; And it has an Edit1 control.
{
Tippy2("EXPLORER WITH EDIT1 only 2 lines of code here....", 1000)
ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
msgbox, ControlSetText happened. `nf_class is %f_class% and f_window_ID is %f_window_id%`nAND f_Edit1Pos is %f_Edit1Pos%
; Tekl reported the following: "If I want to change to Folder L:\folder
; then the addressbar shows http://www.L:\folder.com. To solve this,
; I added a {right} before {Enter}":
ControlSend, Edit1, {Right}{Enter}, ahk_id %f_window_id%
return
}
; else fall through to the bottom of the subroutine to take standard action.
}
*/
else if f_class = ConsoleWindowClass ; In a console window, CD to that directory
{
WinActivate, ahk_id %f_window_id% ; Because sometimes the mclick deactivates it.
SetKeyDelay, 0 ; This will be in effect only for the duration of this thread.
IfInString, f_path, : ; It contains a drive letter
{
StringLeft, f_path_drive, f_path, 1
Send %f_path_drive%:{enter}
}
Send, cd %f_path%{Enter}
return
}
ending2:
; Since the above didn't return, one of the following is true:
; 1) It's an unsupported window type but f_AlwaysShowMenu is y (yes).
; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
; action, so instead do the default action below.
;Tippy2("end was reached.",333)
;SoundBeep, 800, 300 ;this is nice but the whole damn script WAITS for the sound to finish before it continues...
; Run, Explorer %f_path% ; Might work on more systems without double quotes.
;msgbox, f_path is %f_path%
; SplitPath, f_path, , OutDir, , ,
; var := InStr(FileExist(OutDir), "D")
; if (var = 0)
; msgbox, directory does not exist
; else if var = 1
Run, %f_path% ; I got rid of the "Explorer" part because it caused redundant windows to be opened, rather than just switching to the existing window
;else
; msgbox,,,Directory does not exist,1
}
;end of instantexplorer()