其实就是写了几个小函数
- AddTcDirMenu(IniFile)
读取tc配置文件,把tc常用文件夹添加到菜单,必须填写tc配置文件路径
- AddItem(argMenu, argPath, argName := “”, argIco := “”, argForRun := “”, argWorkDir := “”, argMinMax := “”)
添加文件到菜单,可执行文件和文本文件都可以,能自动寻找图标添加。两个必填参数
- AddItemFromeDir(argMenuName, argDir, argItemName := “”, argIco := “”,onlyApp := 1)
从文件夹中批量添加文件到菜单,自动添加图标,可以选择是否只添加可执行文件。两个必填参数
试例代码:
- #singleinstance, force
- #NoEnv
- settitlematchmode, 2
- detecthiddenwindows, on
- ; 全局变量 ;{{{
- global TCEXE := A_ScriptDir . "\..\totalcmd\totalcmd.exe"
- global INIFILE := A_ScriptDir . "\..\totalcmd\wincmd.ini"
- global TcN
- global ItemPath := {}
- global run_arg := {}
- global run_wkdir := {}
- global run_minmax := {}
- ;}}}
- ; 初始化菜单 ;{{{
- menu tray, icon, Ico\lightning.ico
- menu tray, click, 2
- ; menu tray, nostandard
- gosub lm_reflash
- return ;}}}
- lm_reflash: ;{{{ ; 菜单内容配置
- AddTcDirMenu(A_ScriptDir . "\..\totalcmd\wincmd.ini")
- AddItem("lm_net", "d:\Software\AutoHotkey\Scripts\!移动云办公.ahk")
- menu LightM, add, LightM, Reload
- menu LightM, disable, LightM
- menu LightM, Default, LightM
- menu LightM, add
- AddItemFromeDir("LightM", "Tools", "快捷应用(&r)", "Ico\exe.ico")
- menu LightM, add, Tc收藏夹(&t), :TcDir
- menu LightM, add, 常用网站(&g), :lm_net
- menu LightM, add
- AddItem("LightM","C:\Program Files\Everything\Everything.exe","&Everything")
- AddItem("lightM", "powershell.exe","Power&Shell",,,"C:\Users\" . A_UserName)
- AddItem("lightM", "D:\MyProject\jupyter\Scripts\activate.bat","Jupyter","Ico\jupyter.ico",,"D:\MyProject\jupyter\UserDoc","Min")
- AddItem("lightM", "d:\Software\AutoHotkey\AutoHotkey.chm", "&Help", "Ico\help1.ico")
- menu LightM, add, RELOAD, reload
- menu LightM, icon, LightM, Ico\lightning.ico
- menu LightM, icon, Tc收藏夹(&t), Ico\Explorer.ico
- menu LightM, icon, 常用网站(&g), Ico\Internet.ico
- menu LightM, icon, RELOAD, Ico\reload.ico
- return ;}}}
- ; 以下是函数
- AddTcDirMenu(IniFile){ ;{{{ 添加TC常用文件夹
- if(FileExist(INIFILE)){
- loop{
- IniRead OutputVar, %INIFILE%, DirMenu, Menu%A_Index%
- if(OutputVar = "Error")
- {
- TcN := A_Index
- menu TcDir, add, TC打开当前文件夹(&t), TcDirG
- menu TcDir, icon, TC打开当前文件夹(&t), Ico\Explorer.ico
- return
- }
- if(RegExMatch(OutputVar,"^-")){
- menu TcDir, add
- continue
- }
- menu TcDir, add, %OutputVar%, TcDirG
- menu TcDir, icon, %OutputVar%, Ico\Explorer.ico
- }
- }
- } ;}}}
- TcDirG(ItemName, ItemPos, MenuName){ ;{{{ 用tc打开菜单下的文件夹
- global ActivePath
- if(ItemPos=TcN)
- {
- if(ActivePath = "Error")
- path := ""
- else
- path := ActivePath
- }
- else
- {
- IniRead OutputVar, %INIFILE%, DirMenu, cmd%ItemPos%
- path := StrReplace(OutputVar, "cd ")
- }
- run %TCEXE% %path%
- } ;}}}
- AddItemFromeDir(argMenuName, argDir, argItemName := "", argIco := "",onlyApp := 1){ ;{{{ 从文件夹批量添加快捷方式
- if(!argItemName){
- argDir := RegExReplace(argDir, "\\$", "\")
- SplitPath, argDir, argItemName
- }
- loop, files, %argDir%\*.*
- {
- SplitPath, A_LoopFileFullPath,,, OutExtension
- if(onlyApp and OutExtension != "exe" and OutExtension != "Lnk")
- continue
- AddItem(argItemName, A_LoopFileFullPath)
- }
- menu, %argMenuName%, add, %argItemName%, :%argItemName%
- if(argIco)
- menu, %argMenuName%, icon, %argItemName%, %argIco%
- else
- menu, %argMenuName%, icon, %argItemName%, shell32.dll, 4
- } ;}}}
- AddItem(argMenu, argPath, argName := "", argIco := "", argForRun := "", argWorkDir := "", argMinMax := ""){ ;{{{ 添加快捷方式到菜单
- SplitPath, argPath,,, OutExtension, OutNameNoExt
- if(argName)
- OutNameNoExt := argName
- ItemPath[OutNameNoExt] := argPath
- menu, %argMenu%, add, %OutNameNoExt%, ItemRun
- if(argForRun)
- run_arg[OutNameNoExt] := argForRun
- if(argWorkDir)
- run_wkdir[OutNameNoExt] := argWorkDir
- if(argMinMax)
- run_minmax[OutNameNoExt] := argMinMax
- if(argIco = ""){
- if(OutExtension="exe")
- menu, %argMenu%, icon, %OutNameNoExt%, %argPath%, 1
- else if(OutExtension="Lnk"){
- FileGetShortcut, %argPath%, argPath
- menu, %argMenu%, icon, %OutNameNoExt%, %argPath%, 1
- }
- else{
- RegRead, OutputVar, HKEY_CLASSES_ROOT, .%OutExtension%
- RegRead, OutputVar, HKEY_CLASSES_ROOT\%OutputVar%\DefaultIcon
- StringSplit, Icon, OutputVar, `,
- menu, %argMenu%, icon, %OutNameNoExt%, %Icon1%, %Icon2%
- }
- }
- else
- menu, %argMenu%, icon, %OutNameNoExt%, %argIco%
- } ;}}}
- ItemRun(ItemName, ItemPos, MenuName){ ; 运行程序 ;{{{
- Target := ItemPath[ItemName]
- Target2 := run_arg[ItemName]
- run, %Target% %Target2%, % run_wkdir[ItemName], % run_minmax[ItemName]
- } ;}}}
- reload(){ ; 重启脚本 ;{{{
- reload
- } ;}}}
- !s:: ; 注册热键 ;{{{
- ActivePath := Explorer_getpath()
- menu LightM, show
- return ;}}}
- #include Scripts\Lib\Explorer.ahk
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
你为啥不早点发出来?
脚本错了一点,已经修改了。
为什么不早点发出来
新手入门 抱着学习的目的拜读一下 非常感谢