Adapting Web Scraping Routines to Changing Web Pages (AutoHotkey Tip)

When the Horoscope Web Page I Use for E-mails Altered Its Format, I Quickly Adjusted the Script

Last year, I wrote a script that e-mails a daily horoscope to my wife, “E-mail the Daily Horoscope to Yourself (AutoHotkey Trick).” Every morning she receives on her tablet an e-mail containing her daily horoscope. (I don’t send it to myself because I don’t want to know that much about my future—and I don’t listen to advice.) Recently, she pointed out that the e-mail started coming up blank. I immediately realized that the target Web site had changed its source code. (I’ve experienced the same problem with the SynonymLookup.ahk script.) I knew I could repair the Regular Expression (RegEx) in the broken script fairly quickly by following some basic steps:

  1. Access the source code for the target Web page and locate the key text.
  2. Copy the critical portion of the source code, including any unique HTML tags surrounding the target text, then paste the selection into Ryan’s RegEx Tester.
  3. Adjust the RegEx to include key unique tags surrounding the text—then extracting the paragraph.
  4. In the script, replace the old RegEx found in the RegExMatch() function with the new one from Ryan’s RegEx Tester.
  5. Make any necessary adjustments to the RegEx—primarily escaping double quotation marks.

The new horoscope e-mail script now includes more details and a link to the site.
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

Finding Tips at Jack’s AutoHotkey Blogs

With Over 300 Blogs, You Might Find It Difficult to Dig Out the One You Need

I launched Jack’s AutoHotkey Blog in 2015. At that time, I had already published a number of AutoHotkey books but I wanted a way to stay in touch with new users and changes in AutoHotkey.

On the right of the Main Menu bar, you’ll find the “AutoHotkey Topics and Series” menu.

Previously, I had published AutoHotkey articles on the old ComputorEdge Magazine site. However, circumstances and expense forced me to take down the database-driven site. Hundreds of my AutoHotkey tips disappeared from the Web. I didn’t want to do it, but times change. (You can find many of those lost tips in the AutoHotkey books available at ComputorEdge E-Books and even more no-longer-published tips—as well as many more recent ideas—in the book A Motley Assortment of AutoHotkey Tips. The major advantage to using the e-books lies in their organization and searchable indexes.)

When I wrote the new articles for Jack’s AutoHotkey Blog, I avoided duplicating the techniques in previously published articles. While a few important techniques rear their heads on multiple occasions (e.g. the Standard AutoHotkey Windows Clipboard Routine), I concentrate on creating practical applications not previously discussed. My biggest fault lies in the fact that I never finish anything.

Continue reading

Turn Web Addresses into Hotlinks for the AHK File Peek Window (AutoHotkey Tip)

Using the AutoHotkey GUI Link Control to Display AHK File Notes Allows You to Turn Web Links Hot

While perusing the notes in various .ahk scripts using the subroutine ReadNotes—which I had added to the AutoStartupControl.ahk script and discussed in my blog “Peeking at Notes Inside Auto-Startup AHK Script Files (AutoHotkey Startup Control)“—I noticed that many scripts included URLs to reference sites. A common practice used by scriptwriters when giving credit to another script or offering additional information about the source, these sites can offer valuable insight or resources. Usually, a Web address appears as a complete URL including the HTTP(S)://. I wondered, “Wouldn’t it be great to just click a link in the Notes window to load the page?”

Since we write AutoHotkey scripts in plain text, attempting to provide hotlinks inside the file using HTML code (or other techniques) doesn’t make much sense. I can open the file and copy the Web address—pasting it into my browser, but a hotlink in the Notes window would save a lot of time. I immediately switched from using the Text GUI control to the Link GUI control. By inserting the Link control into the AutoStartupControl Notes GUI window, I can turn any URL into a hotlink—as long as I use a Regular Expressions (RegEx).

The Link GUI control in the Notes window can turn any fully formed Web address into a hotlink for immediate access.

Using the Link GUI control comes with a couple of foibles, but, for the most part, it behaves in a manner very similar to the Text GUI control.

Continue reading

A Trick for Creating a New Hotkey from a Subroutine (AutoHotkey Quick Tip)

Use the GoTo Command to Turn the Subroutine for Reading AHK File Notes into a Hotkey for Peeking into Any File Selected in Windows File Explorer

Last time in my “Peeking at Notes Inside Auto-Startup AHK Script Files (AutoHotkey Startup Control)” blog, I discussed the feature in the AutoStartupControl.ahk script for reading and displaying notes from a .ahk source file. The ScriptNotes subroutine uses the data in the Startup folder shortcut to locate the file, then parses out the first set of notes for display. This creates a quick reminder for the purpose and operation of the AutoHotkey scripts automatically loaded when Windows boots.

While a handy tool for the AutoStartupControl.ahk script, the subroutine would offer even more value if I could select any .ahk file in Windows File Explorer and read its notes. For that expanded capability, I need a new Hotkey combination that bypasses reading the Startup folder shortcut and directly accesses the file selected in the Explorer window.

Continue reading

Regular Expressions (RegEx) for Mining Text in Files (AutoHotkey Startup Control)

When It Comes to Extracting Data from Text Files, Nothing Works Like Regular Expressions (RegEx)

Last time, “Peeking at Notes Inside Auto-Startup AHK Script Files,” I added a feature for reading notes inside the .ahk files targeted by shortcuts launched from the Windows Startup folder to the AutoStartupControl.ahk script. This gave me a method for reminding myself how the various auto-startup scripts work. In that blog, I discussed how to find the .ahk file containing the notes. This time, I take a look at how to use Regular Expressions (RegEx) to extract the script notes.

Anyone who follows my blog or reads my books knows that I have a fondness for Regular Expressions (RegEx). The averages person may not find the RegEx system easy to follow or implement, but once the concept clicks, it makes certain aspects of programming much easier—regardless of the programming language. (That’s why I wrote the book A Beginner’s Guide to Using Regular Expressions in AutoHotkey.) When confronted with extracting text or implementing complex replacements, I immediately gravitate toward RegEx. When implemented in scripts such as IPFind.ahk and SynonymLookup.ahk, these enigmatic expressions have made my AutoHotkey life much easier.

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

Add Submenus to the Auto-Startup Menu to Increase Options (AutoHotkey Startup Control)

Submenus Allow AutoHotkey Users to Add Features to Apps Without Needing More Screen Space

Last time in “Adding Startup Folder Shortcuts to a System Tray Menu,” I inserted the Startup folder shortcuts into a System Tray right-click menu. This gave me a method for quickly accessing an auto-load script even when it doesn’t display an icon in the System Tray.

A click of the menu item either opens the script (.ahk) in Notepad or opens the target folder for a compiled executable (.exe) file. While the original menu does the basic job of keeping track of the auto-startup scripts, it only executes one action—opening a script or folder. To expand the capabilities of the Startup Control, we need to add submenus.

Continue reading

Adding Startup Folder Shortcuts to a System Tray Menu (AutoHotkey Startup Control)

By Loading the Startup Folder Shortcuts into a Menu, We Can Access the Apps Even When No Icon Appears in the System Tray

Last time (“Collecting File Information from Windows Folders Using AutoHotkey“), I produced a simple MsgBox displaying the Windows shortcuts found in the Startup folder. When Windows launches, it reads and loads the programs or shortcut targets located in that folder. This provides AutoHotkey users an easy method for auto-loading their most-used scripts. However, the more scripts, the more clutter that appears in the System Tray in the form of AutoHotkey icons. You can reduce the crowding by adding the Menu,Tray,NoIcon command line to each script but then you need a technique for quickly reaching those hidden apps.

By inserting the shortcut names into a separate System Tray right-click context menu, you can both generate a list of shortcuts and provide quick access to the scripts. In this barebones AutoHotkey script, I create a menu that opens either the target script in Notepad (.ahk files) or the folder for the program (.exe files).

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