Longer time ago provided me my friend from this forum function with code which checks if is any file or files selected and use it in script. It works with Windows Explorer and Desktop.
Here's code:
Code: Select all
Selected_Files()
{
; Handles Explorer
IfWinActive, ahk_class CabinetWClass
{
for window in ComObjCreate("Shell.Application").Windows
if window.HWND = WinExist("A")
this_window := window
; If multiple Items selected
if(this_window.Document.SelectedItems.Count > 1)
{
these_files := ""
for item in this_window.Document.SelectedItems
these_files .= item.Path . "`n"
return these_files
}
else
return this_window.Document.FocusedItem.Path
}
; Handles Desktop
if(WinActive("ahk_class Progman") || WinActive("ahk_class WorkerW"))
{
ControlGet, selectedFiles, List, Selected Col1, SysListView321, A
; If multiple Items selected
if InStr(selectedFiles, "`n")
{
these_files := ""
Loop, Parse, selectedFiles, `n, `r
these_files .= A_Desktop . "\" . A_LoopField . "`n"
return these_files
}
else
return A_Desktop . "\" . selectedFiles
}
else
return false
}
for example - by this code can open Notepad empty or with selected file(s):
Code: Select all
F1::
this_path := Selected_Files() ; get selected files(s)
if (this_path)
Run, Notepad "%this_path%" ; if selected, Notepad opens selected file(s)
else
Run, Notepad ; if nothing selected, opens clear empty Notepad
return
Is possible to modify code of function to use with XYplorer and leave desktop handling untouched?
Here's XYplorer info:
Code: Select all
Title: D:\Commodore\Z64K\_SW\NEW - XYplorer 18.60.0100
class: ahk_class ThunderRT6FormDC
exe: ahk_exe XYplorer.exe
Miro