Skip to content

Instantly share code, notes, and snippets.

@yiboyang
Created December 3, 2016 18:33
Show Gist options
  • Save yiboyang/7753ddc48cd66f285697751443218dc1 to your computer and use it in GitHub Desktop.
Save yiboyang/7753ddc48cd66f285697751443218dc1 to your computer and use it in GitHub Desktop.
Win + T to open cmd in current directory
;
; AutoHotkey Version: 1.1
; Language: English
; Platform: Win9x/NT
; Author: Yibo, from Internet
;
; Script Function:
; Define the shortcut Win + T for launching cmd in current folder in Windows Explorer
;
#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.
#NoTrayIcon
SetTitleMatchMode RegEx
return
; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass
; open 'cmd' in the current directory
;
#t::
OpenCmdInCurrent()
return
#IfWinActive
; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCmdInCurrent()
{
; This is required to get the full path of the file from the address bar
WinGetText, full_path, A
; Split on newline (`n)
StringSplit, word_array, full_path, `n
; Find and take the element from the array that contains address
Loop, %word_array0%
{
IfInString, word_array%A_Index%, Address
{
full_path := word_array%A_Index%
break
}
}
; strip to bare address
full_path := RegExReplace(full_path, "^Address: ", "")
; Just in case - remove all carriage returns (`r)
StringReplace, full_path, full_path, `r, , all
IfInString full_path, \
{
Run, cmd /K cd /D "%full_path%"
}
else
{
Run, cmd /K cd /D "C:\ "
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment