Wednesday, August 27, 2008

AHK - Easy edit scripts

This is a simple script that allows you to edit .ahk & .au3 files simply by pressing ctrl+e while they are highlighted in an explorer window.

#NoTrayIcon
#IfWinActive ahk_class CabinetWClass
^e::
ControlGet, List, List, Selected, SysListView321
FName := RegExReplace(List,"U)^(.*)`t.*$","$1")
FPath := ShellFolder()
Ext := SubStr(FName, -3, 4)
If Ext in .ahk,.au3
{
Run, edit "%FPath%\%FName%"
}
Return

; Shell Folder function by Sean
; http://www.autohotkey.com/forum/topic20701.html
ShellFolder(hWnd=0)
{
If hWnd||(hWnd:=WinExist("ahk_class CabinetWClass"))||(hWnd:=WinExist("ahk_class ExploreWClass"))
{
COM_Init()
psh := COM_CreateObject("Shell.Application")
psw := COM_Invoke(psh, "Windows")
Loop, % COM_Invoke(psw, "Count")
If COM_Invoke(pwb:=COM_Invoke(psw, "Item", A_Index-1), "hWnd") <> hWnd
COM_Release(pwb)
Else Break
pfv := COM_Invoke(pwb, "Document")
sFolder := COM_Invoke(pfi:=COM_Invoke(psf:=COM_Invoke(pfv, "Folder"), "Self"), "Path"), COM_Release(psf), COM_Release(pfi), pfi:=0
COM_Release(psi)
COM_Release(pfv)
COM_Release(pwb)
COM_Release(psw)
COM_Release(psh)
COM_Term()
Return sFolder
}
}


* Note - This script requires the COM Standard Library (you can place it in your standard lib directory, or #include it).
* Note - The ShellFolder() function was written by Sean from the AutoHotkey forums.

Explorer Windows Manipulations, COM Standard Library

No comments: