Adding Folders and Files from Windows to AutoHotkey Menus

After a Little Pondering, I Found Adding Windows File Explorer Structures to an Action Menu Simple

I was wrong when I contemplated using the BoundFunc Object to insert folder and file names into an AutoHotkey action menu. At the time, I thought that the AutoHotkey Menu command did not offer enough flexibility to handle the task on its own. Those concerns included:

  1. The limited number of built-in menu variables severely constrained the information available when clicking a menu item.
  2. Duplicate folder names found in any other folder or subfolder would cause a conflict.

Both of these problems have solutions, but I was afraid that I would need to resort to some complicated gymnastics.

Sometimes, we know too much for our own good. With a toolbox full of tricks, we often devise methods which—although they work—make the coding more complex. Then, rather than rethinking the problem, we dig a deeper hole. That’s how I started out with the rewrite of the barebones QuickLinks script. Rather than stripping the question down to the basics, I started looking for solutions to problems that don’t actually exist.

AHK_user dealt with the menu name problem in “QuickLinks (Menu by folder)” by deriving menu names from the full directory path. This ensured no duplicates for any of the submenus. I surmised that I would need to do something similar.

The script loads folders and subfolders into menus and submenus.

Then, it occurred to me, “Why not just use the folder full path as the menu name?” If it worked, I would not need any Regular Expression manipulation of the folder path and name, plus, I would avoid menu name duplication. I realized that I could also drop the BoundFunc Object for passing data. It all seemed too easy.

Continue reading

Barebones AutoHotkey QuickLinks App

After Many Years, It’s Time to Take Another Look at the QuickLink.ahk Script

Since its early beginnings, the QuickLinks.ahk script (originally introduced as a replacement for the missing Windows 8 Start Menu in January 2013) has evolved both through this blog and others working through the AutoHotkey forum. It has grown in complexity which can make it a little difficult to modify for personal use. Recently, I took a closer look at the core of my version of QuickLinks.ahk and decided that the time has come for a rewrite—at least of the central code.

During the intervening years, I’ve learned a few things and feel I can build a cleaner more universal basic program—at least for the main routine. The same may apply to many of the added features. (Sometimes starting over makes the most sense.)

Continue reading

Peeking at Notes Inside Auto-Startup AHK Script Files (AutoHotkey Startup Control)

We Can Track Numerous AutoHotkey Scripts Added to the Startup Folder, But Can We Remember How They All Work? Add a Peek Capability to the Auto-Startup Menu as an App Reminder

With so many different AutoHotkey scripts running, the problem of remembering how they all work arises. I may know that I have an app running but not recall the Hotkey combinations needed to access its features. Each new app creates a new set of memory challenges.

I could write one huge help message, but keeping it up-to-date turns into an unwieldy problem. I need a method for quickly peeking at an apps notes without forcing myself to open the .ahk file.

To accomplish this feat, the new ScriptNotes subroutine in the AutoStartupControl.ahk script must:

  1. Load the shortcut’s target file into a variable.
  2. Extract the script notes from that variable.
  3. Display the extracted notes in a pop-up MsgBox.
Continue reading

Fixing AutoHotkey Web Lookup Scripts

If a Web Page Changes Format, the Data-Extracting Regular Expressions (RegEx) May Need Updating—Fixing the SynonymLookup.ahk Script

When writing a blog, I tend to use certain words over and over again. While rereading early versions, these redundant words jump out at me. Not only do they point out my limited vocabulary, but the repetitions tend to render my blogs a little more starchy and boring. That’s why I often resort to my always-loaded SynonymLookup.ahk script. This app saves time while making me look a little smarter.

The current version of SynonymLookup.ahk script lists more possibilities and marks antonyms (most of the time) with a caution sign (). (Click image for expanded view.)

After I discover a duplicated word, I highlight it, then hit the Ctrl+Alt+L Hotkey combination. A menu of possible replacements pops up. I click on the one that best fits my intent and the new term immediately displaces the original text. I habitually use this script.

When the SynonymLookup.ahk Script Breaks

Over the life of the script, I’ve encountered the menu shown at right a couple of times. This menu pops up whenever the script downloads and scans the source code 10 times without getting a RegEx hit—usually the result of code changes made by the source page Webmaster.

Continue reading

AutoHotkey Tip of the Week: Tricks for Tracking and Activating Target Process Windows

When Implementing Various AutoHotkey Techniques Sometimes We Need to Find Our Way Back to the Proper Window

Most AutoHotkey applications don’t require complicated tracking of process windows. Hotstrings, Hotkeys, and most other techniques do their work in the currently active window. Generally, menus and GUIs automatically return to the original on-top location once they close. However, occasionally circumstances force us to move to other apps or tools—deactivating the current window—before returning to the original target. AutoHotkey offers a couple of techniques for getting back to the right spot on our Windows Desktop.

piechartcartoonFor example, the MousePrecise.ahk app (for precision movement of the mouse cursor) allows users to temporarily enable the mouse accuracy tool in new windows with either a Hotkey combination or a right-click selection from the Windows System Tray icon menu. Since the Hotkey doesn’t change window focus, it works fine, but the act of selecting an item from the System Tray icon menu deactivates the original window. Therefore, before AutoHotkey can include the new app in the active group, it must refocus on that process window and capture its title. Continue reading

AutoHotkey Tip of the Week: Quick Menu for Activating Open Windows

With a Few Modifications, the WindowList.ahk Script Pops Up a Menu of Open Windows for Quick Activation—Plus, How to Detect When a Windows Opens or Closes

I originally used the WindowList.ahk script as a demonstration of how to use the GUI DropDownList control as a list of selection options for activating open windows (included in the Digging Deeper Into AutoHotkey book). Once, while testing someone’s script, it proved very useful. I could not find the GUI window generated by the code. The script had placed the target window somewhere off the screen. The scriptwriter originally used a second monitor—which I didn’t have. The WindowList.ahk script moved the window back into my view.

As I reviewed the script, I realized that building a pop-up menu of open windows could serve a purpose similar to the QuickLinks.ahk script—except, rather than launching apps and Web sites, the menu would activate open windows. Now, that’s something that I can use!

I often keep numerous windows open simultaneously. Generally, I locate a window by hovering over the Windows Taskbar then selecting the image which looks right. It takes a second for the thumbnails to appear, then hovering over each helps me make my selection. But what if I could maintain a menu of all open Windows available in a menu for instant activation? Continue reading

AutoHotkey Tip of the Week: Windows Trick for Adding Embedded Folder Icons to QuickLinks Menus

This Technique Accesses Icons Embedded in Windows Folders for Inserting into Pop-up Menus—Plus, the New Combined Switch/Case Statement QuickLinks QL_GetIcon() Function

I completely rewrote the functions from the last blog for adding icons to the menus in the QuickLinks.ahk script combining the two into a shorter prioritized list using Switch/Case statements. In the process—after investigating how to read icons embedded in Windows folder/directory listings—I discovered an interesting Windows secret. It turns out that this procedure requires a totally different Windows maneuver than that used for reading Windows Shortcut file icons.

The Windows Desktop.ini File

UnHideFiles
Ryan’s UnHideFiles.ahk script makes Windows Registry changes to hide and unhide files.

When you embed an icon into a Windows folder (right-click on the folder name in Windows File Explorer, select Properties and the Customize tap, then click Change Icon… and browse for icons), rather than saving the icon path and icon number in the folder itself—as Windows does for shortcut files—it creates a special hidden file named desktop.ini in that same folder. With Windows set to Show Hidden Files, folder and drives in the View tab of the Folder Options window, you can view the hidden desktop.ini file in that folder. (Tip: You can use Ryan’s UnHideFiles.ahk script to hide and unhide files and folders.) Continue reading

AutoHotkey Tip of the Week: Adding Icons to Menus the Easy Way(?)

Inserting Icons into Your AutoHotkey Menus Makes Options Standout and Easy to Navigate, But You May Need to Prioritize the Methods for Adding Icons

I’ve employed icons in my QuickLink.ahk script for many years, but the process I used for adding them to menu items always felt awkward and messy—too much special-purpose code.

I want the script to standalone without needing much tailoring. Most changes should occur in Windows File Explorer by creating folders or editing shortcuts. Then the QuickLinks.ahk script should read all the Menu items from that folder/file structure—including menu icons. However, my implementation of icons gets a bit sloppy. For my own QuickLinks, I added numerous special lines of code to deal with the inconsistencies in how Windows deals with folder and file icons. I’ve never felt comfortable with how it worked.

My recent work implementing the Switch/Case statements has prompted me to return to my original goal of producing a script needing little or no adapting. That means not only constructing the AutoHotkey menu directly from the folder/file structure shown in Windows File Explorer, but the menu icons themselves should load from those folders and shortcut files without requiring additional unique lines of AutoHotkey code in the script.

Continue reading

AutoHotkey Tip of the Week: Use Regular Expressions (RegEx) to Convert Repetitious AutoHotkey Code

Regular Expressions (RegEx) Can Simplify a Tedious Code Reformatting Problem

Recently, I received the following comment from Thom:

Greetings,

A small improvement to the Autocorrect AHK script. I have been using this script for years and find it very useful. I was always a bit intrigued about the section of ambiguous entries which was commented out and not much use.

I was fascinated to read about your TextMenu function [found in the book Beginning AutoHotkey Hotstrings] to display the various choices. I found a simple way with RegEx to change all the entries in the section.

For example:

::electon::election, electron

To:

::electon::
  TextMenu("election, electron")
Return

I copied and pasted the list into Notepad++ and then ran this find-and-replace.

Find:

(::\w+::)(.+)

Replace:

$1\n TextMenu\(\"$2\"\)\nReturn

And presto it works—some entries need tweaking but it works well. Continue reading

AutoHotkey Tip of the Week: Add Dynamic Submenus to Static Menus Using Menu, DeleteAll

How to Add an Updating Dynamic Submenu to a Static AutoHotkey MenuUnderstanding 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.

HotstringTimeDateMenu
The TimeDate submenu updates each time the top-level menu displays.

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