如何用AutoHotKey将某一个程序的所有窗口无感的最小化

RT, 怎么使用Autohotkey 将某一个程序(比如explorer 或 notepad)的所有窗口无感的最小化.

尝试了一下WinMinimize, 他不支持用Class来过滤 效率也不高.

我的使用场景是因为Groupy偶尔会抽风 所以希望能够定期重启资源管理器然后自动恢复到关闭前的路径.
获取路径, 重启, 恢复之前的路径这部分都解决了没问题, 卡在怎么最小化的恢复.

Run, explorer %folderPath%, ,Min
这个试过 但是会导致窗口无法手动点击任务栏唤起, 所以换思路了 想试试先创建再快速的全部最小化

之前的代码:

; 保存文件夹列表到临时文件
tempFilePath := A_Temp . "\tempPaths.txt"
; FileDelete, %tempFilePath%
Loop, % folderList.MaxIndex() {
    FileAppend, % folderList[A_Index] "`n", %tempFilePath%
}

; 重启资源管理器
Run, taskkill /f /im explorer.exe,, Hide
Process, WaitClose, explorer.exe, 1
Run, explorer.exe

; 等待资源管理器启动
Sleep, 100

; 恢复之前打开的文件夹位置
Loop, Read, %tempFilePath%
{
    folderPath := A_LoopReadLine
    if (folderPath != "") {
        Run, explorer %folderPath%, , Min
    }
}

或者有哪些其他的操作可以完成类似目的?

1 个赞

左侧那两个是上面代码运行后恢复的
右侧那个是不加Min运行出来的

Solution:-

; Function to minimize all Explorer windows
MinimizeExplorerWindows() {
    WinMinimizeAll, ahk_class Explorer
}

; ... (Rest of your script, including saving folder paths, restarting Explorer, etc.)

; ... (After restarting Explorer)

; Restore previous folders and minimize Explorer windows
Loop, Read, %tempFilePath% {
    folderPath := A_LoopReadLine
    if (folderPath != "") {
        Run, explorer %folderPath%
        MinimizeExplorerWindows()
    }
}

试了一下, 好像Class那个名称不对 没有效果
我替换成ahk_class CabinetWClass 似乎也不行, 最后依旧是顶层显示的

https://www.autohotkey.com/docs/v2/lib/WinMinimizeAll.htm 官方文档似乎无论是1还是2都没这个用法

SetTitleMatchMode, 3
ExplorerPath := "C:\folder"
Run, ExplorerPath
WinWait, %ExplorerPath% ahk_class CabinetWClass   ;资源管理器中设置“标题栏显示完整路径”
WinMinimize

WinMinimize不行吗?至少在我这里正常。还是我没抓住重点?

这个方案比较慢而且 很容易被影响
需要现有窗口 然后闪一下再消失 会有比较明显的干扰
另外好像也会造成部分窗口无法恢复, 我更新一下AHK版本看看是否是AHK的bug

这个办法在我这也没复现出无法手动还原窗口的问题:
Run, explorer %folderPath%, ,Min
我用的是1.3版。

提供两个办法:
试试用FileCreateShortcut新建快捷方式,让其以最小化方式启动,然后用Run, %快捷方式全路径%
或者,在Run, explorer %folderPath%, ,Min之后,用winpos获取窗口坐标,如果坐标不在屏幕范围内,或者窗口异常小(我遇到过),就用winmove调整为正常状态

1 个赞