为了更新 AutoHotkey,必须关闭所有正在运行的脚本。可以使用一个简单的脚本终止 AutoHotkey 进程(见下文),但我不知道如何随意重新启动相同的进程。目前,我在更新后重新启动计算机(以启动 Windows 启动文件夹中的 AHK 脚本)。
Windows 显然不允许同时启动多个文件。因为我启用了几十个 AutoHotkey 脚本,所以手动启动它们是不可行的。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Loop
{
#Singleinstance force
Process, Close, Autohotkey.exe
}
答案1
; FileDelete, %A_Desktop%\my running scripts.ini
; Get a list of all running AHK scripts:
DetectHiddenWindows, ON
WinGet, id, list, ahk_class AutoHotkey
Loop, %id% ; retrieves the ID of the specified windows, one at a time
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
SkriptPath := RegExReplace(title, " - AutoHotkey v" A_AhkVersion )
If InStr(SkriptPath, A_ScriptFullPath)
continue
; Store the path of each running script in an INI-file and terminate it:
IniWrite, %SkriptPath%`n, %A_Desktop%\my running scripts.ini, my_running_scripts
WinClose, %SkriptPath% ahk_class AutoHotkey
}
; Run %A_Desktop%\my running scripts.ini
; Create a new script in the startup folder that starts the same scripts after rebooting:
FileAppend,
(
IniRead, my_running_scripts, `%A_Desktop`%\my running scripts.ini, my_running_scripts
Loop, parse, my_running_scripts, ``n
Run `%A_LoopField`%
; FileDelete, `%A_ScriptFullPath`%
ExitApp
)
, %A_Startup%\my running scripts.ahk
ExitApp
return
如果您想从桌面手动重新启动脚本,请替换%A_Startup%
为。%A_Desktop%