AutoHotKey 帮助,匹配字符和替换

AutoHotKey Help, matching character and replacing

我的保存功能,请注意我不想知道更好的保存方法或更正我的保存代码,我只需要帮助我需要它的部分自动删除额外的非 required/old 括号保存时生成: 这是保存按钮:

buttonSave:
FileAppend,
(
nprocess,exist, %Input%
nprocess,priority, %Input%, %PriorInput% 
}
), C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk
MsgBox, 0, Saved, %PriorInput% Priority to %Input% has been saved.

如何让 AutoHotkey 找到 } 并删除任何匹配字符 },然后在文件末尾添加一个 },并使其循环?

我有一个保存功能,输出是这样的:

loop
{
process,exist, Steam.exe
process,priority, Steam.exe, 
}
process,exist, Steam.exe 
process,priority, Steam.exe, 
}

我想让它找到结尾 } 和中间 } 删除它们,然后在最后添加一个 }。如果你保存,它总是在底部添加一个括号。

我会使用这样的东西(循环导致高 CPU 利用率):

#NoEnv
#SingleInstance Force
#Persistent

Menu, Tray, Add
Menu, Tray, Add, Add Process, Add_Process
Menu, Tray, Default, Add Process ; doubleclick the tray icon to add a new process

SetTimer, set_priority, 500
return

set_priority:
Process,exist, Notepad.exe
Process,priority, Notepad.exe, L
; Add Process
return

Add_Process:
InputBox, ProcessName, ProcessName, Enter a Process.
if !ErrorLevel
InputBox, priority, priority, Enter a priority.
if !ErrorLevel
{
    text =
    (       
    Process,exist, %ProcessName%.exe
    Process,priority, %ProcessName%.exe, %priority%
    ; Add Process
    )
    FileRead, Contents, %A_ScriptFullPath%
    if not ErrorLevel ; Successfully loaded
    {
        StringReplace, Contents, Contents, `; Add Process, %text% 
        FileAppend, %Contents%, %A_ScriptDir%\Temp.ahk
        Contents =  ; Free the memory
    }
    FileMove, %A_ScriptDir%\Temp.ahk, %A_ScriptFullPath%, 1  ; overwrite existing file
    reload
}
return
    buttonSave:
FileRead, Contents, C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk
if not ErrorLevel ; Successfully loaded
{
    StringTrimRight, Contents, Contents, 1  ; remove the end }
    FileAppend, %Contents%, C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk
    Contents =  ; Free the memory
}
FileAppend,
(
process,exist, %Input%
process,priority, %Input%, %PriorInput% 
}
), C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk
FileMove, C:\Users\%A_UserName%\Desktop\AutoSetup\Temp.ahk, C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk, 1  ; overwrite existing file
; Run, edit C:\Users\%A_UserName%\Desktop\AutoSetup\Settings.ahk
MsgBox, 0, Saved, %PriorInput% Priority to %Input% has been saved.
; reload  ; if Settings.ahk is included in this script
return