I just wrote a very simple function to toggle a setting and the corresponding menu item (e.g. you might have a "shut down after finished" item in the tray menu, which would toggle the shutDown variable as well as check/uncheck the menu item):
; toggle setting and corresponding menu item toggleSetting(ByRef var, menuName, menuItem) { If (var = True) { var := False Menu, %menuName%, Uncheck, %menuItem% } Else { var := True Menu, %menuName%, Check, %menuItem% } }Not sure if anyone will ever need this - but I certainly will, so storing it here is the safest way to make sure it won't get lost...
Example script:
Menu, Tray, NoStandard Menu, Tray, Add, Shut down, toggleShutdown Loop { If (shutDown = True) { MsgBox, I'll shut you down! ExitApp ; "Shutdown, 9" deemed unsafe for the purpose of this demo } Sleep, 1000 } toggleShutdown: toggleSetting(shutDown, "Tray", "Shut down") Return toggleSetting(ByRef var, menuName, menuItem) { If (var = True) { var := False Menu, %menuName%, Uncheck, %menuItem% } Else { var := True Menu, %menuName%, Check, %menuItem% } }
UPDATE: See below for improved version.