Skip to content

Instantly share code, notes, and snippets.

@mkp246
Last active November 17, 2017 07:25
Show Gist options
  • Save mkp246/ba3663d5ccf0bb3837944ce5729f6d14 to your computer and use it in GitHub Desktop.
Save mkp246/ba3663d5ccf0bb3837944ce5729f6d14 to your computer and use it in GitHub Desktop.
CTRL+SHIFT+C copies selected file/directory paths to clipboard in windows explorer and CTRL+ALT+T on windows explorer opens cmd there(non-admin)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#NoTrayIcon
#SingleInstance force
#IfWinActive ahk_class CabinetWClass
^+c:: Explorer_GetSelection()
Explorer_GetSelection(hwnd="") {
hwnd := hwnd ? hwnd : WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (class="CabinetWClass" or class="ExploreWClass" or class="Progman")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
if(ToReturn){
clipboard := RegExReplace(ToReturn, "^[\r\n]+|[\r\n]+$","")
;MsgBox %clipboard%
}
}
^!t::
id := WinActive("A")
WinGetClass, Class, ahk_id %id%
ControlGetText, path, ToolbarWindow323, ahk_id %id%
path := SubStr(path, 10)
;MsgBox %path%
run, "C:\Windows\System32\cmd.exe", %path%
#IfWinActive
@mkp246
Copy link
Author

mkp246 commented Nov 17, 2017

currently doesn't handle special library folder like Pictures, Documents..
need to manually map those to absolute folder.
if we can get the status of last command then we can rerun with different root path,
OR if path doesn't start with *$[A-Z]:* then add user directory as prefix to path(will not fix all problem, if you looking at someone else's user directory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment