AutoHotkey Tip of The Week: Evaluating Deprecated AutoHotkey Commands

As Time Passes, You May Notice More and More Deprecated AutoHotkey Commands in the Online Documentation—When Should You Rewrite Your Scripts and When Should You Ignore the Changes?

While working on the latest version of the QuickLinks.ahk script, I saw that the syntax for the Loop (files & folders) command for the reading the names of directories and files had changed in the online AutoHotkey documentation. (It’s about time that I noticed since it changed back in 2015.) In the original program I used:

Loop, C:\Users\%A_UserName%\QuickLinks\*.*, 2 , 0


Loop, %A_LoopFileFullPath%\*.*, 1 , 0

The powers-that-be deprecated that form of the command substituting:

Loop, Files, C:\Users\%A_UserName%\QuickLinks\*.*, D


Loop, Files, %A_LoopFileFullPath%\*.*, FD

While the new syntax seems a little clearer, it appears to act in the same manner as the original (still operational) form of the command. A person may ask, “Why the change the command at all?”

Many other deprecated commands have benefitted from an upgrade to a function. For example, the out-of-favor IfInString command yields to a preferred combination of the If command and the InStr() function. This type of If command-function/expression alliance makes possible the elimination of a multitude of If command variations:

IfEqual, Var , Value          ; if Var = Value
IfNotEqual, Var , Value       ; if Var != Value
IfLess, Var , Value           ; if Var < Value
IfLessOrEqual, Var , Value    ; if Var <= Value
IfGreater, Var , Value        ; if Var > Value
IfGreaterOrEqual, Var , Value ; if Var >= Value

By using the If (expression) form of the conditional statement along with the appropriate expression or function (possibly a replacement function for a deprecated command), we can drop many other specialized commands such as those shown above. The benefits from these changes appear obvious, but, as in the case of the Loop, File command, the reward seems a little more obscure.

Getting Ready for AutoHotkey Version 2.0

CoverImage200Two years ago I wrote a series of blogs comparing AutoHotkey version 1.1 and AutoHotkey version 2.0 which I posted on my “A Peek at the Coming AutoHotkey V2.0” page. I even offered advice on “AutoHotkey Version 2.0—Should I Wait for It?.” As I review those blogs I see that little has changed (including my advice)—except both AutoHotkey V1.1 and AutoHotkey V2.0 have improved substantially. Unlike other scripting languages looking at a major upgrade/change, rather than losing support, the older V1.1 has gained from the improvements in V2.0.

For example, I have no doubt that the new Hotstring() function and Switch command found in V1.1 resulted from their addition to AutoHotkey V2.0. Rather than forcing users to make a tough decision about changing from V1.1 to V2.0, most of the significant upgrades in V2.0 also appear in V1.1—although using a slightly different syntax. The problem is that the two versions are not compatible so upgrading older scripts is not easy.

When first starting out with AutoHotkey, you can choose either version. You’ll find significant differences in format. AutoHotkey V1.1 primarily uses a command structure while V2.0 replaces those commands with functions. This affects how you see and think about the building of your scripts. While you’ll find more support for V1.1 in scripts, forums, and books, experienced programmers may prefer the function approach found in V2.0. Brand new AutoHotkey scripters may do well to start with V1.1. The only wrong decision is doing nothing.

Switching from AutoHotkey Version 1.1 Commands to AutoHotkey Version 2.0 Functions

Full Disclosure: I offer a number of examples of V2.0 code in my AutoHotkey books but the vast majority of the content centers around writing V1.1 scripts. Many of the tips apply to both versions as long as you adapt the scripts to correct syntax.

Tip: When reviewing AutoHotkey V1.1 commands online, you can jump directly to the associated V2.0 function by clicking v1 at the top of the page and selecting v2—and vice versa. (See the image above.)

Other than the increased functionality for a number of the commands, another possible reason for deprecating and changing the syntax in V1.1 commands may be to move them closer to the look and feel of the parallel functions in V2.0—although they will never completely match.

Comparing V1.1 Loop, File Command to V2.0 Loop File Function

In AutoHotkey V1.1, the Loop (files & folders) command takes the following form:

Loop, Files, FilePattern [, Mode]

Note the comma after the Loop command (Loop, Files).

In AutoHotkey V2.0, the Loop (files & folders) function takes the following form:

Loop Files FilePattern [, Mode]

They look very similar. However, the comma which appears in the V1.1 command cannot show up in the V2.0 function. V2.0 assumes the set of parentheses that we normally associate with functions. Either the space character or a matching open parentheses must appear between terms Loop and Files:

Loop(Files, FilePattern [, Mode])

Also, with the exception of the word Files, the V2.0 parameters evaluate expressions—requiring the enclosing of all strings in quotes. The V1.1 command accepts plain text parameters. You must use %var% text replacement or forced expressions (%) to add variable contents to the V1.1 command.

Change to the Loop, File Command?

While many of the replacements for deprecated AutoHotkey V1.1 commands offer advantages over the original, the Loop, File command does not demand the same level of attention. While I will only use the newer command in the future, I don’t feel compelled to scour my older scripts in order to update the deprecated command. If you do eventually switch to 2.0, the replacement command might make it a little easier. By the time V2.0 becomes “the” AutoHotkey version to use, I imagine someone will have written a script for converting code from V1.1 to V2.0—if that hasn’t already occurred.

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.)


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.)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s