Skip to content

Instantly share code, notes, and snippets.

@Zeturic
Created August 15, 2020 20:15
Show Gist options
  • Save Zeturic/8634f46205376a8a8f4485fe8faa8f8e to your computer and use it in GitHub Desktop.
Save Zeturic/8634f46205376a8a8f4485fe8faa8f8e to your computer and use it in GitHub Desktop.
; small AHK script to copy a filename to the clipboard
; defaults to ctrl + shift + c
^+c::
clipboard := Explorer_GetSelection_Basename()
return
Explorer_GetSelection_Basename(hwnd="") {
fullname := Explorer_GetSelection(hwnd)
SplitPath fullname, ToReturn
return ToReturn
}
; autohotkey.com/board/topic/60723-can-autohotkey-retrieve-file-path-of-the-selected-file/?p=383073
Explorer_GetSelection(hwnd="") {
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process = "explorer.exe")
if (class ~= "Progman|WorkerW") {
ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
Loop, Parse, files, `n, `r
ToReturn .= A_Desktop "\" A_LoopField "`n"
}
else if (class ~= "(Cabinet|Explore)WClass") {
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
}
return Trim(ToReturn,"`n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment