Using Parts to Build a New AutoHotkey Script (HowLongInstant.ahk)

While Many Users Find the Original GUI Based HowLong Script Valuable, Combining Snippets of Code Creates a New Instant HowLong Script

Last time in “Extracting Multiple Dates from Text Using AutoHotkey RegEx,” I wrote a Regular Expressions (RegEx) that copied the first and last date (in a variety of formats) found in a selection from a document or Web page. (I recently updated that RegEx to make it more robust.) That represented the first step in building an instant HowLongYearsMonthsDay.ahk script. The goal, as defined by the reader, included highlighting a section of text which bounds two dates, pressing a Hotkey combination, then immediately calculating and displaying the timespan—no delaying the process with an input GUI or clicking a calculate button. As with many new scripts, I took pieces of it from other scripts and integrated them to produce a new one.

The chunks I used to produce the new script included:

  1. The Standard Clipboard Routine for capturing the selected text.
  2. The RegEx for identifying and capturing the target dates. (Discussed in my last blog.)
  3. The DateConvert() function found in the DateStampConvert.ahk script for formatting the parsed dates as the standard TimeDate stamp (YYYYMMDD).
  4. The HowLong() function found in the HowLongYearsMonthsDays.ahk script for calculating the timespan between the two TimeDate stamp parameters.
  5. A MsgBox for instantly displaying the results.
Continue reading

Working with AutoHotkey Date Formats and Timespan Calculations

AutoHotkey Date and Time Calculations Require Special Handling—Check Out This List of How-to’s for Working with Dates

Over the years, I’ve written a number of blogs and many chapters about formatting and calculating dates, but one of my AutoHotkey apps that I think most demonstrate the full range of these capabilities include the scripts HowLongYearMonthDay.ahk and DateConvert.ahk.

DateConvertSend
When combined with the HowLongYearMonthDay.ahk script, the DateStampConvert.ahk script directly converts various ambiguous date formats selected in documents or Web pages into the standard datetime stamp format for inserting into the time-span calculating GUI pop-up.

Rather than using AutoHotkey commands for converting the standard datetime stamp into one of the numerous worldwide date formats, this conversion tool does the reverse and reformats selected dates into the universal datetime stamp.

Continue reading

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

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: A Look at the New Switch/Case Command

In the DateStampConvert.ahk Script, Rather than Using a Series of If-Else Statements (or the Ternary Operator), the New Switch Command Sets Up Case Statements for Alternative Results—Plus, Easily Add Conversions for Spanish, German, French, and Italian Date Formats

Over a year ago, I used a cascading series of the ternary operators to convert English text month names into their numeric values within a single function (“Use the Ternary Operator to Create Conditional Case Statements or Switches“). The ternary operator shortcut acts as If-Else statements in abbreviated form.

DateConvertSend
In the DateStampConvert.ahk script, a technique similar to Switch/Case statements converts the name of a month into its corresponding numeric value.

Continue reading