Can AutoHotKey retrieve file path of the selected file ?
I would like to use AutoHotkey as following:
- select one file in Win. Explorer and with user defined key combination I would like to execute one exe/bat file over selected file. For that I need to retrieve selected file path and to send it to my exe/bat ... how to do this ? :idea:
Thanks,
bets regards,
Zoki.
Loop, FilePattern [, IncludeFolders?, Recurse?]Specifically the Special Variables Available Inside a File-Loop section of the AHK help file.
The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter KeyLooperDemo Key Spammer TinyClickRecorder GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
F1::MsgBox, % gst() ; example gst() { ; GetSelectedText or FilePath in Windows Explorer by Learning one IsClipEmpty := (Clipboard = "") ? 1 : 0 if !IsClipEmpty { ClipboardBackup := ClipboardAll While !(Clipboard = "") { Clipboard = Sleep, 10 } } Send, ^c ClipWait, 0.1 ToReturn := Clipboard, Clipboard := ClipboardBackup if !IsClipEmpty ClipWait, 0.5, 1 Return ToReturn }
F1:: selection := FC("explorer","","selection") Loop % selection.len() run % "notepad.exe """ selection[A_Index] """" return
Using AHK build with objects and my FileContainer object. Also see Explorer Selection Hotkeys.
#SingleInstance force x2 = 186 ;This is where the Notepad icon is on my desktop y2 = 429 ;put the coords for your batch file or exe icon here Run Explorer.exe WinWaitActive, ahk_class CabinetWClass MsgBox,4160,Drag&Drop Demo, Highlight the file you want D&D'd in Explorer and press F1. Watch the magic happen. Return F1:: Click Sleep 200 CoordMode,Mouse,Screen MouseGetPos, x1,y1 MouseClickDrag, Right, x1,y1,x2,y2,50 CoordMode,Mouse,Relative Return
Select the "Open With" item in the resulting menu and you're on your way.
The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter KeyLooperDemo Key Spammer TinyClickRecorder GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Content of my_path.ahk file is:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#a::
selection := FC("explorer","","selection")
Loop % selection.len()
run % "notepad.exe """ selection[A_Index] """"
return
and if executed I get message:
Error: Call to nonexisting function.
Specifically: FC("explorer", "", "selection")
...
i tried to download in the same folder yours Everything.zip with ShellFileOperation.ahk, Prefs.ahk, Container.ahk, FC.ahk...but it still does not works.
Could you please tell me please what exactlly to do ? additionally if compiled and executed FC.exe AntiVir reports it as TR/Dropper.Gen virus ! ?
Br,
Zoki
As for the antivirus thing, it's a false positive -- don't worry about it (or tell the AntiVir people it is a false positive so they fix it).
So to get it to work for just my_path.ahk, take the "everything" files and put them in a folder named "lib" (such that "my_path.ahk" and "lib" are both in the same folder together). Then it should run fine. This way is the "standard library". The "user library" is for when you have lots of different scripts that might want to use FC.ahk.
1. FC requires a build of AHK that supports objects. That means, if you are using the original ahk, you may have problems with the modules
2. Did you include the libraries with the #Include directive in your program? If not. you won't get the functions to work.
Since you're getting an error indicating that FC() is a non existent function, it sounds like you're not linked, so you might want to check any include statement you have to see if it's mistyped. This assumes that a) you did #Include FC.AHK somewhere in your code and, it's on the right path.
The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter KeyLooperDemo Key Spammer TinyClickRecorder GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter KeyLooperDemo Key Spammer TinyClickRecorder GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Hmm I know C/C++/C# language but fast geting into AutoHotKey is not possible :shock:
I modified my_path.ahk file so that it display just selected file:
#a::
selection := FC("explorer","","selection")
MsgBox selection
return
1. I am getting Message Box but nothing is writen..any clue why?
2. Could you shortlly explain also the line:
run % "notepad.exe """ selection[A_Index] """"
what does it means "%" ? and what tripple """ ? the best would be link to hel file because entering just "%" in chm help bring no matches...
best regards,
Zoki
the first will display 4 while the second will display "2+2":
MsgBox % 2+2 MsgBox 2+2
"" is how you put a quote in a string. so:
str:="this is a quote:"""
For your messagebox problem:
MsgBox % selection
this would also work:
MsgBox %selection%
the peace of the code bellow...still does not work ... do we have some new ideas ? :idea: or we run out of those
#a::
selection := FC("explorer","","selection")
MsgBox %selection%
return
I just get message box without any content.
best regards,
Zoki