Rather Than Increasing the Length of a System Tray Menu, Add Submenus—Plus, How to Use Menu Names (A_ThisMenu) for Conditional Actions
When I decided to add two more recipes to the Jack Stuffed Cheeseburger script, I ran into the problem of adding too many items (one for each step in each recipe) to the System Tray right-click menu. In the original, Cheeseburger.ahk script, I only included four steps in the menu (Ingredients, Prepare, Cook, and Serve). However, after inserting the Animal-Style Cheeseburger and the Jack Stuffed Cheeseburger (Animal Style) into the script, the number of recipe increments jumped from four to 18—plus an additional Print Recipe option for each burger. Also, since many of the steps use the same (or similar names), I needed a method for identifying each step with the proper recipe. When increasing the number of AutoHotkey menu options, cumbersome lists of items commonly crop up. You can fix these bloated menus by using submenus. Continue reading →
Note: I changed the CheeseburgerRecipe.ahk script in a number of ways—a few of which I plan to discuss in future AutoHotkey Tips. For now, I confine myself to highlighting the use of the GoTo command. For specific changes, see the comments at the top of the CheeseburgerRecipe.ahk script.
Adding Options to the Cheeseburger Recipe
I found another recipe at FoodNetwork.com which replicates the In-N-Out Animal-Style Cheeseburger recipe. Copying the same AutoHotkey techniques I used for the Jack Stuffed Cheeseburger, I added the new steps for this recipe to the script. Since the System Tray menu grew too crowded, I implemented submenus for each recipe. (See image below.)
The primary differences between the Jack Stuffed Cheeseburger and the Animal-Style Cheeseburger include caramelizing onions, mixing a special sauce, burgers with no embedded cheese, preparation of the buns, and frying the burgers with mustard. While more involved than the first recipe, the new recipe might satisfy the “Animal” in anyone. But, what if you wanted a Jack Stuffed Cheeseburger Animal Style?
You could write an entirely new recipe for a Jack Stuffed Cheeseburger Animal Style but that would include a great deal of redundancy. By using the AutoHotkey GoTo command, we combine the redundant steps of the two recipes to create a third variation.
For the new Jack Stuffed Animal Style Cheeseburger, the recipe starts at the Label point Stuffed_Animal_Ingredients: which includes the ingredients for the Animal Style Cheeseburger plus the added Jack cheese (for stuffing) and varied meat and cheese amounts. Using the GoTo command, AutoHotkey jumps directly to the Animal_Onions: pointer for caramelizing the onions.
Since the process jumps into the middle of the Animal Style Cheeseburger subroutine, when the Animal Style Cheeseburger – Onions window closes, it automatically drops into the Animal_Sauce: routine. Next, the recipe must GoTo the Jack Stuffed Cheeseburger Label named Prepare: for shaping the burgers with Monterey Jack cheese inside. In order to make this jump decision, AutoHotkey must identify the currently running recipe subroutine: either Animal Style Cheese Burger (no Goto) or Jack Stuffed Animal Style (GoTo).
The initial menu selection tells us which recipe track to follow. The menu name (A_ThisMenu) identifies the Jack Stuffed Animal Style recipe:
Placing this condition into the MessageSetup: subroutine identifies the origin of any mixed-use menu steps. AutoHotkey determines the proper path by checking the value of the StuffedAnimal variable. For example, after the Animal_Sauce: window, the process uses the following check:
If (StuffedAnimal = 1)
If running the Jack Stuffed Animal Style sequence (StuffedAnimal = 1), AutoHotkey jumps to the Prepare: point of the Jack Stuffed Cheeseburger routine. Otherwise, the Animal Style Cheeseburger continues dropping through its steps.
This same conditional format creates the jumps from Prepare: to the Animal_Buns: point and from Animal_Buns: to the Stuffed_Animal_Cook: point for the Jack Stuffed Animal Style steps. This process creates a new variation from older recipes without rewriting redundant steps. Often using the GoSub command (for Go Subroutine) works better, but in this situation, GoTo makes the routine act as if it’s one continuous series of steps.
GoTo Versus GoSub
To understand the difference between the GoTo command and the GoSub command, know that when a subroutine finishes, the GoSub command returns to the next line in the original calling routine, while the GoTo command does not. In most cases, since it returns to the same spot in the script, you’ll probably find the GoSub command (or a function) more appropriate. But if you know that you don’t want to return to that point, then feel free to use GoTo—but you better know where you plan to end up.
A common usage of GoSub runs the subroutine then returns to the next line after the calling line. For example, I moved the loading of the recipe variables for each step out of the auto-execute section of the script into separate Label subroutines, then replaced each with a single GoSub command. This made the script more readable by greatly reducing the length of the auto-execute section. In place of the code, I inserted the following GoSub command statements:
However, using the GoSub command in the mixed recipe scenario for the Jack Stuffed Cheeseburger Animal Style would have caused more problems than it solved. For example, if the GoSub command appeared in place of GoTo, then each call would create a new return point. That means clicking the Cancel button would cause the script to jump to the last GoSub call rather than exiting the thread. In many cases, jumping back would cause unwanted effects (e.g. display an inappropriate step from another recipe). In fact, even running through the entire recipe without canceling would cause an untold number of displays of various steps. After encountering the last Return in the subroutine, the final Return jump executes more GoSub commands—each creating an additional Return point. The GoTo command keeps it clean, allowing an exit with any Return encountered in any recipe sequence. To the user, each recipe (including the mixed) looks like a continuous set of steps.
While probably best avoided if GoSub or a function can do the job, the GoTo command works well in scripts emulating flow charts and plays an important role in decision trees. In those special situations, knowing where you are (and where you’re going) may be more important than where you’ve been.
While Other Techniques Exist for Printing Directly from AutoHotkey, Make It Easy by Using Print Drivers from Other Programs
When I first considered printing from the cheeseburger recipe script, I didn’t realize how complicated printing from AutoHotkey can get. With any printing, a number of factors come into play. First, each printer model uses particular print drivers. Second, the format of the document affects the output and drivers. Third, you may need to choose from multiple printers. Continue reading →
Once You Know How AutoHotkey Label Names Work, You Can Add More Tricks to Your Bag of AutoHotkey Skills
While in the past I often used the terms AutoHotkey Label and subroutine interchangeably, that’s not exactly accurate—although the two terms maintain a close relationship. Misunderstanding how Label names work can be a source of errors for new AutoHotkey script writers. However, knowing the differences between what constitutes a Label and a subroutine opens up new scripting opportunities. The CheeseBurgerRecipe.ahk script uses little-known Label behavior to either walk through all the steps or jump to individual sections of the recipe for a “Jack Stuffed Cheeseburger.” Continue reading →
While You Don’t Often See Television Chefs Using Computers, AutoHotkey Offers Guidance When Cooking “Jack Stuffed Cheeseburgers” at Home
* * *
While I came up with a pretty cool barebones recipe script for this AutoHotkey blog, I’m not sure how well computers and cooking mix. From what I’ve seen, professional chefs don’t have much time to mess with technology—except for possibly writing cookbooks—in which case, I would refer them to “Why AutoHotkey for Writers, Bloggers, and Editors?.”
* * *
Using a computer while cooking presents a challenging task. Although looking up a recipe on a smartphone works great, poking at the device with fingers covered in cookie dough proves impractical. Ideally, any kitchen machine is lightweight and stands upright on its own.
Although a little pricey, the Microsoft Surface Pro (or another less expensive Windows ultralight laptop computer) might do the job. Large enough to read the screen, yet easy to move around a cooking area, these computers help any budding chef or dietician who needs to check recipes—as long as no one dumps boiling water on the keyboard. For size and convenience, finding equipment more practical than a lightweight laptop proves difficult. Continue reading →
Dynamically Switch the Actions of a Running AutoHotkey Script with a Simple Click of a System Tray Right-Click Menu Item
From Rick Corbett:
Talking of “Adding Actions to Windows System Tray Icon Menu“, perhaps you would consider writing about using—for example—ToggleCheck, MenuItemName to amend a running script dynamically, i.e. change something (like toggling logging to a file versus a MsgBox), then reload.
* * *
That’s an excellent question, Rick! Often, after loading a script, we want to either turn features off and on or change how they function. Adding separate Hotkeys or rewriting scripts becomes wearisome. But, what if we could add a feature to the Windows System Tray Icon Context Menu (right-click) which either toggles an action on and off or completely changes how it works? AutoHotkey offers a straightforward way to get it done. Continue reading →
Ten Reasons Why Every Student Should Use the Free AutoHotkey Windows Tools! AutoHotkey Helps You So Much Academically That You’ll Think You’re Cheating! Plus, It’s Delicious Brain Food and Helps Get You a Job!
Using AutoHotkey should be mandatory for every student from high school on through college! Not merely because learning AutoHotkey invigorates the brain cells (which it does!), but it makes all your Windows tasks so much easier that it seems unsporting. AutoHotkey takes the grunt work out academia making learning fun…almost.
(If you know a student who uses a Windows computer, then do him or her a favor by sending him or her a link to this article. If he or she doesn’t already know about AutoHotkey, he or she will thank you profusely.)