; File encoding: UTF-8
/*
AutoHotkey 版本: 1.1.9.0
操作系统: Windows XP/Vista/7
作者: sunwind <1576157 qq="" com="">
博客: http://blog.youkuaiyun.com/liuyukuan/article/details/7411291
脚本说明:此为脚本用于打开Office、Scite等软件中 打开的文档路径。
脚本版本: 2012-12-23版
Timestamp:2012年12月23日14:40:22
*/
;2012-12-23 更新Scite路径获取方式为com调用,即使标题栏没有显示全部路径也能工作。
;2012-03-31 改热键为win+del,因为我多数是为了清理没用文档,删除当前打开的文件。
;2012-03-31 增加:对非office软件 则打开程序所在目录功能。
;2012-03-31 增加 :可打开SciTE 、EmEditor文档所在目录(前提是其标题栏显示文档路径)
;对于notepad等程序需要增加也个case标签单独处理,可以通过先设置各个程序支持在标题栏中显示路径,然后解析路径的方式.本想弄个通用的用WMI方式查询cmd_line内容,但是如果运行了记事本,再open,打开文本文件的话,文件路径是不在cmd_line中的,残念.
#del:: ;打开office文档所在目录。非office软件打开程序所在目录。
WinGet, _ProcessPath, ProcessPath, A
_DocPath:=getDocumentPath(_ProcessPath)
TrayTip,,%_DocPath%,10
Run,% "Explorer.exe /select, " _DocPath
Return
getDocumentPath(_ProcessPath)
{
SplitPath,_ProcessPath,Process_Name,Process_Dir,,Process_NameNoExt
value:=Process_NameNoExt
If IsLabel( "Case_" . value)
Goto Case_%value%
Else
Goto Case_Default
Case_WINWORD: ;Word OpusApp
Application:= ComObjActive("Word.Application") ;word
ActiveDocument:= Application.ActiveDocument ;ActiveDocument
Return % ActiveDocument.FullName
Case_EXCEL: ;Excel XLMAIN
Application := ComObjActive("Excel.Application") ;excel
ActiveWorkbook := Application.ActiveWorkbook ;ActiveWorkbook
Return % ActiveWorkbook.FullName
Case_POWERPNT: ;Powerpoint PPTFrameClass
Application:= ComObjActive("PowerPoint.Application") ;Powerpoint
ActivePresentation := Application.ActivePresentation ;ActivePresentation
Return % ActivePresentation.FullName
Case_SciTE: ;;打开SciTE当前文件所在目录
Return % GetCurrentFilePath(GetSciTEInstance())
Case_EmEditor: ;;打开EmEditor当前文件所在目录
WinGetActiveTitle _Title
SplitPath,_Title,name,dir
Needle:=" - "
StringSplit,_name,name,%Needle%
FullName:=dir . "\" . _name1
Return % FullName
Case_AkelPad:
WinGetActiveTitle _Title
SplitPath,_Title,name,dir
MsgBox %dir%
Needle:=" - "
StringSplit,_name,name,%Needle%
FullName:=dir . "\" . _name1
Return % FullName
Case_Notepad:
WinGet pid, PID, A
wmi := ComObjGet("winmgmts:")
queryEnum := wmi.ExecQuery(""
. "Select * from Win32_Process where ProcessId=" . pid)
._NewEnum()
If queryEnum[Process] {
CMDLine := Process.CommandLine ; 获取进程命令行
RegExMatch(CMDLine, "i)\s+(.*)", ff_) ; 正则匹配命令行参数
;~ RegExMatch(process.CommandLine,"i).*exe.*?\s+(.*)",CMDLine_1)
StringReplace,ff,ff_1,`",,All
if ff<>
Return % ff
else
Return % _ProcessPath
wmi := queryEnum := Process := ""
}
Case_Default:
Return % _ProcessPath ; 其他程序打开程序所在目录
}
GetCurrentFilePath(scite)
{
if !scite
{
MsgBox, 16, Error, Can't find SciTE!
ExitApp
}
return scite.CurrentFile
}
GetSciTEInstance()
{
olderr := ComObjError()
ComObjError(false)
scite := ComObjActive("SciTE4AHK.Application")
ComObjError(olderr)
return IsObject(scite) ? scite : ""
}
;~ 增加打开当前程序的路径,热键设置为win+end。
#end:: ;仅是打开当前激活窗口的程序所在目录。不常用
WinGet, _ProcessPath, ProcessPath, A
Run,% "Explorer.exe /select, " _ProcessPath
Return
获取打开的文档的路径
最新推荐文章于 2020-12-05 22:57:58 发布