Usage:
Where's this video I'm playing/file I'm editing? Win+S.
Where's this application I'm using? Win+A.
#SingleInstance, Force
CursorWatchTime = 100
SetTimer, WatchCursor, %CursorWatchTime%
; Alternatives that always open a new window
;#a:: Run, Explorer /n`,/select`,"%sFilePath%"
;#s:: Run, Explorer /n`,/select`,"%FilePath%"
#a::
SetTimer, WatchCursor, off ; Don't want values changing now
Run, %AppOutDir%
WinWaitActive, ahk_class CabinetWClass
WinGetClass, ActiveWinClass, A
If ActiveWinClass = CabinetWClass
Send %AppOutNameNoExt%
SetTimer, WatchCursor, %CursorWatchTime%
Return
#s::
SetTimer, WatchCursor, off ; Don't want values changing now
Run, %OutDir%
WinWaitActive, ahk_class CabinetWClass
WinGetClass, ActiveWinClass, A
If ActiveWinClass = CabinetWClass
Send %OutNameNoExt%
SetTimer, WatchCursor, %CursorWatchTime%
Return
Return
WatchCursor:
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
WinGet, pid, PID, ahk_id %id%
VarSetCapacity(sFilePath, 260)
VarSetCapacity(sCmdLine, 512)
pFunc := DllCall("GetProcAddress"
, "Uint", DllCall("GetModuleHandle", "str", "kernel32.dll")
, "str", "GetCommandLineA")
hProc := DllCall("OpenProcess", "Uint", 0x043A, "int", 0, "Uint", pid)
hThrd := DllCall("CreateRemoteThread", "Uint", hProc, "Uint", 0, "Uint", 0
, "Uint", pFunc, "Uint", 0, "Uint", 0, "Uint", 0)
DllCall("WaitForSingleObject", "Uint", hThrd, "Uint", 0xFFFFFFFF)
DllCall("GetExitCodeThread", "Uint", hThrd, "UintP", pcl)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pcl, "str", sCmdLine, "Uint", 512, "Uint", 0)
DllCall("psapi\GetModuleFileNameExA", "Uint", hProc, "Uint", 0, "str", sFilePath, "Uint", 260)
; DllCall("psapi\GetProcessImageFileNameA", "Uint", hProc, "str", sFilePath, "Uint", 281)
DllCall("CloseHandle", "Uint", hThrd)
DllCall("CloseHandle", "Uint", hProc)
; Normal cases
If not InStr(sCmdLine,"""") ; without "
{
StringGetPos, PosOfFilePath, sCmdLine, exe, R1
StringTrimLeft, FilePath, sCmdLine, PosOfFilePath+4
;tooltip, % FilePathOnly
SplitPath, FilePath, OutFileName, OutDir, ,OutNameNoExt
}
else ; with "
{
StringGetPos, PosOfFilePath, sCmdLine, ", R2
StringTrimLeft, FilePathOnly, sCmdLine, PosOfFilePath
StringReplace, FilePath, FilePathOnly, ", , ReplaceAll
SplitPath, FilePath, OutFileName, OutDir, ,OutNameNoExt
}
; Special cases
If InStr(title,"PsPad -")
{
StringGetPos, PosOfFilePathPSPad, title, [
StringTrimLeft, FilePathPSPadOnly, title, PosOfFilePathPSPad
StringReplace, FilePathNoLeftBracket, FilePathPSPadOnly, [
StringReplace, FilePath, FilePathNoLeftBracket, ]
SplitPath, FilePath, OutFileName, OutDir, ,OutNameNoExt
;Tooltip, %OutDir%
}
SplitPath, sFilePath, AppOutFileName, AppOutDir, ,AppOutNameNoExt ;Application name and path
;ToolTip, %sFilePath%`n%FilePath%
;Tooltip, %AppOutFileName% %AppOutDir% %AppOutNameNoExt%
;ToolTip, %sFilePath%`n%sCmdLine%`nPID %pid%`nahk_id %id%`nahk_class %class%`n%title%`nControl: %control%
;ToolTip, %OutFileName% %OutDir%
Return
I hope someone can fix/fill in what doesn't work and optimize the code. Thanks to everyone whose code made this possible.
Problems:
- Selection fails to get the right one if there are multiple files with the same name if extensions are hidden. Should use some other method than typing. I tried ShellNavSelect <!-- m -->http://www.autohotke... ... 912#271912<!-- m --> but couldn't make it work.
The alternatives always select the right one but:
- Opens a new window always because if the window is already open, without /n (which opens a new duplicate window) /select fails to select the file.
- Fails if command line parameter doesn't contain a file but an option, e.g. -r.
______________
Keywords: command line parameters, find, go to file being edited, open Explorer path of file




