How do i open the command prompt from inside a folder, and have it point to that same directory? I've exhausted the shift+right-click in folder trick, doesn't work for me. I need this for ffmpeg.
I use a third party file explorer (xplorer2), so i need a method that will work regardless of the file explorer being used.
How to open command prompt from inside a folder w/Autohotkey?
- MilesAhead
- Posts: 232
- Joined: 03 Oct 2013, 09:44
Re: How to open command prompt from inside a folder w/Autohotkey?
If it is not Explorer then I think you may be limited to a kludge where you send a key sequence to go up one folder(such as Alt Up Arrow), sleep 250 ms or so, then send ^c to get the directory into the clipboard. Then send Enter to go back where you started. Not smooth. But if you always use the same file explorer it may be neater to use the Spy to find out the ClassNN of the edit control that has the folder name in it. See ControlGet n the help.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."
- MilesAhead
name on it and take the blame."
- MilesAhead
Re: How to open command prompt from inside a folder w/Autohotkey?
script from user tmplinshi , start this script , open a folder and use (example) ctrl+alt+a
example with ffmpeg ( used shortpath ) create a helpfile
Code: Select all
;DOSCommandHere ctrl+alt+a
;-------- https://autohotkey.com/boards/viewtopic.php?t=5796&p=33858#p33858 user tmplinshi ---
^!a::cmdHere()
cmdHere() {
If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
WinHWND := WinActive()
For win in ComObjCreate("Shell.Application").Windows
If (win.HWND = WinHWND) {
dir := SubStr(win.LocationURL, 9) ; remove "file:///"
dir := RegExReplace(dir, "%20", " ")
Break
}
}
Run, cmd, % dir ? dir : A_Desktop
}
return
example with ffmpeg ( used shortpath ) create a helpfile
Code: Select all
setworkingdir,%a_scriptdir%
pr=C:\M_SmallPrograms\FFMPEG\ffmpeg.exe
f1=%a_desktop%\%a_now%_FFMPEG_HELP.txt
ifnotexist,%pr%
{
msgbox,Download first ffmpeg.exe
run,https://ffmpeg.zeranoe.com/builds/
exitapp
}
Loop,%pr% ;- create shortpath from path above
SP2= %A_loopFileShortPath%
runwait,%comspec% /c %sp2% -h>"%f1%",,hide
run,%f1%
return
- MilesAhead
- Posts: 232
- Joined: 03 Oct 2013, 09:44
Re: How to open command prompt from inside a folder w/Autohotkey?
Skan's code to get path from URL should work in most cases.
Plus he still have the issue it will be used in a third party file manager.
Code: Select all
; function by SKAN on AHK forums
;
PathCreateFromURL( URL )
{
if (! URL)
return ""
VarSetCapacity( fPath, Sz := 2084, 0 )
DllCall( "shlwapi\PathCreateFromUrl" ( A_IsUnicode ? "W" : "A" )
, Str,URL, Str,fPath, UIntP,Sz, UInt,0 )
return fPath
}
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."
- MilesAhead
name on it and take the blame."
- MilesAhead
Re: How to open command prompt from inside a folder w/Autohotkey?
I can stick with the third party explorer if that will make it easier
- MilesAhead
- Posts: 232
- Joined: 03 Oct 2013, 09:44
Re: How to open command prompt from inside a folder w/Autohotkey?
It should be pretty simple. There should be a class name you can see with the Spy for the pane you are in, and most often they name the class of the edit line that holds the folder path "Edit1". In all cases I have seen it is a single line edit control. Just use ControlGet with the Line command to get the path to pass to ffmpeg.Dubs wrote:I can stick with the third party explorer if that will make it easier
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."
- MilesAhead
name on it and take the blame."
- MilesAhead
Re: How to open command prompt from inside a folder w/Autohotkey?
Forgive me I'm not fully understanding of Autohotkey, I have managed to grasp the basics, and the basics to using Radial Menu with it, but I'm still quite a noob when it comes to creating new scripts and stuff. My end goal is to open the cmd via Radial Menu while inside the file explorer, and have it point to the current folder, so that I can do conversions with ffmpeg. Apologies for not making this clear earlier.
I remember setting up a key to check for the technical name of the current window, but I'm not sure if this is what you are looking for:
I remember setting up a key to check for the technical name of the current window, but I'm not sure if this is what you are looking for:
Re: How to open command prompt from inside a folder w/Autohotkey?
Impossible.I use a third party file explorer (xplorer2), so i need a method that will work regardless of the file explorer being used.
There are a few ways to do this (and in general, to automate things):
- Take whatever the user does (you do), and emulate it - Send, Click, whatever.
- Use an interface designed for use by other applications; e.g. create a COM object and call some methods.
- Scrape what information you need from the program, then use that to perform the action in AutoHotkey.
#2 requires that each file explorer has such an interface. Windows Explorer has one (accessed via the Shell.Application object). Other file explorers probably don't even have one, let alone one the same as Explorer.
#3 requires that you can get the information from the program. For example, if it shows the full path of the directory in the title bar, you can easily get it with WinGetTitle and open a command prompt with Run. You could probably make this work with many file explorers (or even text editors), but it still requires that they show the path in the window title. Some file explorers don't by default, or just don't. You'd also need a generic way to extract just the path, without the other parts of the title (like the program's name).
If none of that gives you a usable idea, I'd suggest reading the manual.
I would think that any alternative file explorer that can't be customised to open a command prompt when you press a hotkey (without AutoHotkey) isn't worth its salt. Apparently you can customise the keyboard shortcuts in xplorer2; maybe you can bind custom commands to keyboard shortcuts?
I've never used xplorer2, but assuming I've found the right program, the manual indicates that you can run commands in the address bar. That being the case, another method could be to focus the address bar and just run the command $ cmd or $ start cmd (the $ prefix is explained in the manual).
Of course, if the path of the folder is in the window title, WinGetTitle + Run should be much more reliable.
Who is online
Users browsing this forum: Google [Bot], Kawlinz, mebelantikjaya, NinjoOnline and 299 guests