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

Strip HTML Tags from Text (AutoHotkey Quick Tip)

Use This AutoHotkey Trick to Remove HTML Code from Any Text

Last time in “Alternative Web Page HTML Download Techniques (AutoHotkey Tip),” I mentioned how I updated the GooglePhraseFix.ahk script by aaston86 to get it working again and make it a little more robust. The script uses a Google search page to autocorrect common expressions and people’s names. (It only works if Google thinks you may have made an error.)

For example, if you type “Ralph Nadal” the Spanish tennis player, selecting the name and using the CTRL+ALT+G Hotkey combination changes “Ralph Nadal” to “Rafael Nadal.” It only works for obvious possibilities, but may come in handy for correcting hard to remember spellings (i.e. “Jocavic” turns into “Djokovic”).

I added the phrase “Showing results for ” to the script as a search key in the Google results page. Google includes the phrase when it senses that you may have made a mistake. The original script used the StringReplace command to remove some HTML code and correct any apostrophes ('):

   StringReplace, clipboard, match2, <b><i>,, All
   StringReplace, clipboard, clipboard, </i></b>,, All
   StringReplace, clipboard, clipboard, ',', All

The StringReplace command can work for unchanging HTML tags but you need to add the command for each tag (or set of tags). By using the RegExReplace() function, you can remove all HTML code with one command.

HTML Tag Stripping Regular Expressions (RegEx) Using the RegExReplace() Function

The selected section of the Google page now includes a lot more HTML code than merely italics <i> and bold <b>. Using the following expression removes it all:

   var := RegExReplace(var,"<.+?>")

You don’t need to know anything about AutoHotkey Regular Expressions (RegEx) to use the above RegExReplace() function. The command removes all text found in var bounded by the arrow brackets (< … >).

Suppose you want to copy all the text from a Web page to a file. You could use the URLDownloadToFile command to copy the page source code, then execute the above RegExReplace() function to remove all of the HTML code. Only the plain text remains.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)

jack

This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

AutoHotkey Speed Tips

A Collection of Techniques for Speeding Up Your AutoHotkey Scripts

I recently received the follow message from an AutoHotkey user perusing my blogs:

Jack, you can’t post false statements like this:

“However, the ternary does not provide better performance than the traditional If-Then-Else statement format.”

The ternary operator is inarguably faster than if/else and I encourage you to try this yourself.

I recently switched the core logic of my JSON parser from If/Else to ternary and saw an incredible speed increase. To the point where I only use If/If Else/Else statements when absolutely necessary (Ex: If I must have a loop in the middle of a check).

You can code entire blocks using nothing but ternary as long as you use proper parentheses, commas, and function calls.

There is a very well done AHK forum post that covers script optimizations and they report that ternary performs FORTY PERCENT FASTER than if/else statements.

Not sure if hyperlinks are allowed in these comments, so instead I’ll advise googling “AHK How to optimize the speed of a script as much as possible.” The first result should be the article in question. Pages 1 and 4 have tons of script speed gold in them.

I hope you’ll consider correcting/updating this article.

Groggy Otter

Comment on “AutoHotkey Toggles and the Ternary Operator”

I wrote that blog five years ago and I don’t know that I was talking about performance speed. I think I was referring to how the two expressions operate. In any case, I used a poor choice of words and have drawn a line through the comment.

Continue reading

Finalizing an AutoHotkey Script

While No One Actually Ever Completes an AutoHotkey Script, Some People Get Much Closer Than Others

Last June I started a series of blogs on “Finishing and Polishing AutoHotkey Scripts.” (Ironically, I never finished either the script or the series of blogs.) I wrote six articles aimed at making a script more flexible and user-friendly. Once I had added a menu bar to the GUI window, my chosen menu items provided a map to the ultimate finished product. In the course of that work, I introduced a number of methods for enhancing the program.

Continue reading

Collecting File Information from Windows Folders Using AutoHotkey

In Order to Manage Scripts Launched from the Windows Startup Folder, We Must First Know the Folder’s Contents

Last time in “Auto-Loading AutoHotkey Scripts When Booting Windows,” I highlighted the problem introduced by launching scripts from the Windows Startup folder on boot up—too many AutoHotkey icons in the System Tray might overwhelm the status bar. We can turn off the icons, but that’s like turning out the lights in an unlighted, windowless room full of furniture. You don’t know what’s where. We need a handy system for consolidating the information sitting in the Startup folder without making it too intrusive.

This time I demonstrate one technique for consolidating the Startup folder data for display. I have yet to settle on how I want to display the information and use the data. I see a number of possibilities:

  1. A single MsgBox listing the Startup shortcuts—the simplest, yet least flexible approach.
  2. A single System Tray icon right-click menu listing the Startup shortcuts—more flexible but limited in action creating techniques.
  3. A GUI window using a ListView control displaying the Startup folder’s shortcut data—the most flexible and powerful approach but more complicated to implement.
Continue reading

Moving Forward with AutoHotkey Chrome.ahk Tools

My Last Three Blogs Offer a Basic Introduction to Installing and Running the Chrome.ahk Web Page Automation Tools—Find More Resources for these Useful Functions

In my earlier blogs, I posted a beginner’s introduction to GeekDude’s Chrome.ahk Web page automation tools:

I wrote these columns to bridge the gap between the novice-level user and the videos produced by GeekDude and Joe Glines—even causing me to take time to allow the techniques to ferment in my brainpan. While the videos provide excellent information, they assume a certain level of user experience. Hopefully, my blogs provide enough insight to allow new users to:

  1. Develop a basic understanding of how Chrome.ahk functions facilitate the completion of Web forms while highlighting the complications from HTML and Javascript code.
  2. Make a decision about whether they will continue to pursue these Web automation techniques.

After this reference blog, unless someone asks me specific questions about Chrome.ahk, I intend to move on to other topics.

Continue reading

Sending Multiple Saved Data Items to Documents and Forms in AutoHotkey (Temporary Hotkeys)

Sometimes We Want Single-key Hotkeys to Work Only for Short Periods of Time

The press of a single key provides the easiest method for inserting data into an edit field or document. In AutoHotkey, you can activate any key as that quick action single-key with either a Hotkey or Hotstring. However, in the normal course of work, that technique renders that keyboard action useless for anything else. To get the convenience of one-key instant activation, we must activate that Hotkey when needed—only in specific circumstances and for short periods of time.

AutoHotkey offers a number of different methods for accomplishing this instant key action. Which we choose depends upon what we want to do. In this blog, I look at three different methods:

  1. Use the Hotkey command to temporarily turn Hotkeys on then off again.
  2. Use the #If directive to designate conditional Hotkeys.
  3. Temporarily pause the script after Hotkey activation, then deactivate Hotkeys upon resuming.

While each temporary Hotkey works in a similar manner—activating only when needed—each has its advantages and disadvantages.

Continue reading

AutoHotkey Object-Oriented Notation for Associative Arrays (A Short Intro)

Special Object-Oriented Syntax Makes It Easier to Retrieve Array Data

I hesitate to discuss Object-Oriented Programming (OOP) in AutoHotkey. I haven’t work with it enough to provide the insight I would like when addressing a topic. When reading online tutorials, I have a tough enough time understanding the explanations. I have yet to see a tutorial that makes it simple. So, I concentrate on the pieces that get results right now without going too much into the weeds.

From what I’ve read, OOP acts as the de facto standard for professional programmers—not without controversy (“Object-Oriented Programming Is Bad?“). They say that the planning and organization which comes with using OOP makes life easier for multiple people toiling on large projects. While this approach to programming may work for large projects, it does not necessarily make life easier for short apps such as most AutoHotkey scripts.

Continue reading

Track Graphic Line Measurement Segments Using AutoHotkey Arrays

When Refreshing the MouseMeasure.ahk Invisible GUI Graphics Layer, AutoHotkey Uses a Simple Array of Associative Arrays to Track the Data

In my last blog (“Measure Multiple Line Segments with an AutoHotkey On-Screen Ruler“), I introduced multi-segment lines for estimating distances of non-linear routes. When refreshing the graphics to animate the moving line, all previously fixed segments need redrawing. Objects-based arrays provide the best method for tracking and regenerating these lines.

Each leg of the journey corresponds to a simple array element containing an associative array of data. The white box displays the key:value data saved in MyArray[4].

The difference between pseudo-arrays, simple arrays, and associative arrays can get confusing. For the novice AutoHotkey scriptwriter, unfamiliar Object-Oriented Programming (OOP) notation can make understanding the code even more difficult—especially if you attempt to learn OOP from online documentation.

You may think you need to choose between the traditional AutoHotkey syntax and OOP coding, but you don’t! AutoHotkey allows you to mix-and-match most OOP and classic AutoHotkey syntax—as long as you understand how they integrate.

Continue reading