; Menu Tray, NoIcon
Menu Tray, NoStandard
Menu Tray, Add, % AutoRun("MenuIni"), AutoRun
Menu Tray, Add, Выход, _Exit
IniRead FirstRun, % A_ScriptName ".ini", Pref, FirstRun, 1
If FirstRun
IniWrite % AutoRun("On"), % A_ScriptName ".ini", Pref, FirstRun
Return
End::AutoRun("Off")
Esc::
_Exit:
ExitApp
AutoRun(p:="Toggle") {
static tAdd := "Добавить в автозагрузку", tRem := "Убрать из автозагрузки"
ShortcutPath := A_StartupCommon "\" A_ScriptName ".lnk"
If e:=FileExist(ShortcutPath) {
FileGetShortcut % ShortcutPath, linkTarget,, linkParam
If (linkTarget != A_ScriptFullPath)
FileCreateShortcut % A_ScriptFullPath, % ShortcutPath, "%A_ScriptDir%"
; If AHK not install - FileCreateShortcut "%A_AHKPath%", % ShortcutPath, "%A_ScriptDir%", "%A_ScriptFullPath%"
}
If (p = "MenuIni")
Return e ? tRem : tAdd
If e {
If (p != "On")
FileDelete % ShortcutPath
Else
ErrorLevel := true
}
Else {
If (p != "Off")
FileCreateShortcut % A_ScriptFullPath, % ShortcutPath, "%A_ScriptDir%"
Else
ErrorLevel := true
}
If Not ErrorLevel
Menu Tray, Rename, % e ? tRem : tAdd, % e ? tAdd : tRem
}