不幸的是,六年后的Windows 10仍然存在相同的问题,而在Windows 10的最新更新中,我发现某些快捷方式/程序不再是
幂等的!特别是Putty,在同一会话中我有多个快捷方式。
因此,我使用AutoHotKey并修改了该线程中共享的功能(基于LifeHacker的本文),以便它使用INI文件来跟踪每个快捷方式。这不会使用每个程序的Windows标题,因为如果您将screen或SSH用于另一台服务器,这可能会在Putty中更改,这是我个人希望保留的功能!
还包括一个函数“ DeleteINIEntry()”,您可以创建一个快捷方式以使其从INI文件中删除一个UniqueName条目。或者,您也可以手动编辑和更改文件。
INIFilePath := "C:\Temp\AHK.ini"
RunOrSwitchWin( UniqueName, AppPath )
{
global INIFilePath
IniRead, TargetID, %INIFilePath%, windowids, %UniqueName%
ActiveID := WinExist("A")
; cannot use '=' here as comparing an integar to string doesn't work well
IfEqual TargetID, %ActiveID%
{
WinMinimize
return
}
WinGet, AllIDs, list
Loop, %AllIDs%
{
this_id := AllIDs%A_Index%
ifEqual TargetID, %this_id%
{
DllCall("SwitchToThisWindow", "UInt", this_id, "UInt", 1)
return
}
}
run, %AppPath%,,, CurrentPID
WinWait ahk_pid %CurrentPID%
IniWrite, % WinExist("A"), %INIFilePath%, windowids, %UniqueName%
return
}
DeleteINIEntry()
{
global INIFilePath
InputBox, UniqueName, Delete INI Entry, Enter UniqueName
If ErrorLevel = 0
IniDelete, %INIFilePath%, windowids, %UniqueName%
return
}
^!3::DeleteINIEntry()
; Putty shortcuts.
; ^!1 is NOT idempotent and will run it over and over again.
^!1::run "C:\Program Files\PuTTY\putty.exe"
^!2::RunOrSwitchWin( "session1", "C:\Program Files\PuTTY\putty.exe -load session1" )
如果您不希望窗口最小化,则只需将WinMinimize行注释掉(在前面加上;),它将仅聚焦在活动窗口上。