How to Add an Updating Dynamic Submenu to a Static AutoHotkey Menu—Understanding the Difference Between Menu, DeleteAll Command and Menu, Delete Command
When I first wrote the HotstringMenu.ahk script, I planned it as a substitution for ambiguous or multiple option Hotstring text replacements. After typing one of the activation strings, a menu of alternative replacements pops-up. Since the Hotstring menus include many varied item lists, it made sense to create each only when needed. However, when I decided to combine a number of these menus into a group under one main menu, preloading the numerous static submenus seemed more practical. That left me with one problem. Some menus, such as current time and date insertion, need updating each time they pop up.
Once created, AutoHotkey menus sit idle as static tools waiting for the Menu, Show command—at least until deleted. While each subroutine called by a clicked menu item can produce variable results, the contents of the menu itself remain fixed. (Menu items do not accept variables as item names.) That means scripts which use the MenuItemName variable as dynamic output won’t update—unless the script deletes the menu items, then recreates them. If used as a submenu, the DateMenus.ahk script for inserting various current time and/or date formats into documents needs such an active menu. Continue reading