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

Use the GoTo Command to Traverse Long Subroutines (Part Four: Finishing AutoHotkey GUI Scripts)

Sometimes the GoTo Command Makes Life Easier without Creating Perverse Effects

This next portion of the InstantHotstring.ahk menubar implementation did not go as I had expected. I thought that I would break up the routine launched by the Save Hotstrings button into separate subroutines or functions, then call each as appropriate for the corresponding Save/Append Hotstrings menu items (as seen in the image). I didn’t look forward to it because I knew it could get a little confusing. Some items would require multiple subroutine calls while others would need to just run—depending upon the menu selections made by the user.

I didn’t want to write redundant subroutines, but separating the various features of the complete routine required more than merely adding Return commands to encapsulate the code. I finally ask myself, “Why not insert AutoHotkey Labels into the main Save routine and use the GoTo command to jump my way through the decision points?”

Continue reading

Radically Improving AutoHotkey GUI Apps with Menu Bars

While GUI Menu Bars Make Your AutoHotkey Apps More User-Friendly, the Benefits from Adding One to Your Script Go Far Beyond the Obvious

* * *

This blog represents the first in a series that revisits the InstantHotstring.ahk script introduced and developed in previous posts—starting with “Create Instant Hotstrings Using the AutoHotkey Hotstring() Function.” In this new endeavor, I add a GUI menu bar which significantly alters my view of the app. The benefits of implementing a GUI menu bar greatly exceed its functional use.

* * *

I consider most of my scripts demonstrations of how to implement AutoHotkey possibilities—not completed applications. I rarely go back to do all the little things that will make a script a finished product—in two senses of the word: virtually completed and fine-tuned. Many of my favorites (QuickLinks.ahk, MousePrecise.ahk, SynonymLookup.ahk, AutoCorrect.ahk, ChangeVolume.ahk, etc.) don’t require much additional work—if any—although, a script rarely achieves perfection. Most of my scripts use menus, Hotkeys, or Hotstrings while running in the background—not requiring extra visual bells and whistles. However, once you base an AutoHotkey script on a GUI (Graphical User Interface) pop-up window, the need for additional finishing touches increases—especially if it opens and saves files.

One of the best methods for finishing an AutoHotkey GUI app involves adding a menu bar. (You might also argue that the writing of a GUI script should start with a menu bar. It creates a road map to the finished product.) On the surface, a GUI menu bar makes the app more user friendly, but, more importantly, the process forces you to rethink the design and structure of your script.

Continue reading

New Intermediate Online AutoHotkey Course for Novices from “The Automator”

A New Udemy Course “Intermediate Autohotkey—Getting Past the Basics” from Joe Glines—Autohotkey Automation Guru

Not everyone learns in the same manner. Some of the best programmers I know taught themselves from scratch. They looked up the commands and figured out the rest themselves. They learn more advanced techniques by reviewing code written by other aficionados. While they do seek help for advanced topics, they don’t usually need beginning books or introductory courses. But, most people don’t fit into that category.

Continue reading

AutoHotkey Tip of the Week: Guidelines for AutoHotkey Function Libraries

When Using Function Libraries, You Don’t Need to Embed Your Functions into Each of Your AutoHotkey Scripts—But Sometimes Keeping Them Close Works Out Better

In the past two blogs, “Dynamic Regular Expressions (RegEx) for Math Calculating Hotstrings” and “The Eval() Function for Hotkey Math Calculations and Text Manipulation“, I highlighted two different powerful, auxiliary (not built-in) AutoHotkey functions: RegExHotstrings() and Eval(). Normally, you might embed a user-defined function inside your script but these two functions take up quite a few lines of code. Plus, you might want to use those same functions in a number of different scripts. Adding them to each script can get a little cumbersome—even when using the #Include directive.

Fortunately, when loading a script, if AutoHotkey doesn’t find a directly called function inside the script, it automatically searches the special Function Libraries. But, before you race to put all of your functions in one of those Libraries, you should consider a number of factors. 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

AutoHotkey Tip of the Week: Use the Variadic Function Parameter for an Unknown Number of Values in Hotstring Menus

What To Do When You Don’t Know How Many Values You Will Use? For Hotstring Menus, the Variadic Function Parameter Allows a Variable Number of Arguments or Direct Array Input

Variadic Function: One which accepts a variable number of arguments.

MenuEmojiTagsLight Bulb!In the blog, “AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis“, I discussed switching from the deprecated StringSplit command to  StrSplit() function before posting the scriptAfter posting my new HotstringMenu.ahk script on the AutoHotkey forum, I received the following comment from the user Delta Pythagorean. I have mixed feelings about the recommended changes:

You can simplify this down by making the parameter variadic and letting the user chose which label to set the menu to work off of.

:x:brb::HotStringMenu("MenuLabel","Hello",,"Goodbye","See you later!")

MenuLabel:
  MsgBox, % "You said: " A_ThisMenuItem
Return

HotstringMenu(Handle, TextList*) {
  For Each, Item in TextList
    Menu, MyMenu, Add, % Item, % (Item != "") ? Handle : ""
  Menu, MyMenu, Show
  Menu, MyMenu, DeleteAll
}

I like the overall concept. This change to the HotstringMenu() function expands its capabilities by adding a selectable subroutine Label name and uses a variadic parameter which allows the functions to accept an unknown number of values. Continue reading

AutoHotkey Tip of the Week: How to Combine Multiple Scripts into One—August 19, 2019

Design Your Scripts to Either Run as Stand-alone Apps or Use the #Include Directive to Integrate into a Master Script without Modification

Light Bulb!Cover 200 Border

The cool thing about this tip is that, after you implement these techniques—without any additional changes—you can run your AutoHotkey script as an independent app or quickly add it to a master script. 

In “Chapter Eleven: How to Write Easy-Merge AutoHotkey Scripts” from the book Beginning Tips for Writing AutoHotkey Scripts, I outline steps for writing scripts which easily combine with other scripts without conflict. This allows the AutoHotkey user to run multiple apps without needing to launch each script individually. (It also prevents the accumulation of numerous AutoHotkey icons in the Windows System Notification Tray.) If you employ these basic design tips when writing your apps you’ll find that you don’t need to do any rewrites when combining useful scripts. Continue reading

Fixed the InstantHotstring.ahk Script Slow Hotstring Loading Problem

New Version of InstantHotstring.ahk Script Now Available!

I’ve rewritten the LoadHotstrings subroutine in the InstantHotstring.ahk script (alternate download) to overcome the slowdown created by using the pre-existing routines found in the original script, “AutoHotkey Script Speed Problems (Scripting Insights).” I simplified things by limiting the subroutine to:

  1. Adding Hotstrings directly from the file without extra processing—no interaction with the DropDownList GUI control.)
  2. Checking for duplicated or changed Hotstrings within a single variable.
  3. Activating each Hotstring as its added.

AutoHotkey exports the DropDownList GUI control contents just once into a single variable and only writes the new DropDownList after processing the entire target file. The test file of over 1000 Hotstrings loads in one to two seconds—depending upon the weather. (The old routine could take up to 70 seconds for that same file.)

You can find the new code (InstantHotstring(FastLoad).ahk) and the old code (InstantHotstring(SlowLoad).ahk) at the InstantHotstring.ahk section of the ComputorEdge Free AutoHotkey Scripts page.

I’m currently working on blogs which discuss both the philosophical and technical aspect of rewriting the subroutine.

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

Formatting Fonts and Colors in AutoHotkey GUI Window Controls

Guidelines for Setting Text Styles in AutoHotkey GUI (Graphical User Interface) Controls—You Can Make Your GUI Windows Easier to Read by Changing the Text Font and/or Color of Individual Controls

While AutoHotkey doesn’t offer the same detail control of color, font, and text style that you get in graphics programs, you can enhance your GUI pop-up windows with well-placed style changes. But to get the most from your adjustments, you need to understand how AutoHotkey executes these modifications.
Continue reading