Accessing Web Pages (AutoHotkey Tips)

Find a Consistent Relationship in URLs to Redirect Web Pages

A while back I wrote a script which accessed the AutoHotkey online documentation quickly bringing up information about commands and variables. It took advantage of a hidden index in AutoHotkey.com which loaded key pages. However, as happened at the time, relying upon that index does not guarantee access. As with any Web page, things change.

The online documentation is currently going through some modifications. Possibly, in preparation for future use with the coming AutoHotkey version 2.0, we see a number of new revisions. With those alterations, the secret index has once again disappeared. That means much of my earlier work no longer functions as designed. I’ve decided to completely redo my AutoHotkey reference app with the following goals:

  1. Drop reliance on any hidden index to quickly return AutoHotkey command and variable information.
  2. Add simultaneously support for both AutoHotkey V1.1 commands and the parallel V2.0 functions.
  3. Add support for locating changes in V2.0 not directly correlating with V1.1 commands.

JacksLibraryBookDeal250To do this I’ll need to create a lookup table which both loads V1.1 command pages and finds the appropriate V2.0 pages.

Over the course of the next few weeks, I intend to develop this new AutoHotkey Quick Reference script. With modification, you can apply the techniques I use to pulling information from any Web page. You can consider the fact that I use current V1.1 and the future V2.0 data to create this script almost incidental.

*          *          *

AHKNewCover200
This New 2018 Beginner’s Guide includes peeks at the future parallel AutoHotkey V2.0 code.

In this first step, I look at the relationship between the AutoHotkey V1.1 pages and the V2.0 pages. As long as that relationship remains consistent, I can create AutoHotkey scripts which match the related pages. While I use the following techniques to locate matching AutoHotkey V2.0 commands from the URL of a related V1.1 Web page in the online AutoHotkey documentation, they work in any situation where you want to jump directly from one Web location to another related page.

When using the built-in link at the top of the page (see image below) to jump from the V1.1 AutoHotkey documentation to V2.0, the switch always loads the top-level documentation page. While fine for accessing the V2.0 opening page, I would like it so much better if the link would jump from the specific V1.1 command page to the matching V2.0 function page. Maybe, at some point, the v1 ⇒ v2 switch at the top of the page will take you to the corresponding V2.0 function, but until that time, AutoHotkey offers a couple of alternative approaches.

AHK Version 2.0
The v1 ⇒ v2 switch at the top of the AutoHotkey documentation page jumps to the top-level of the respective V2.0 documentation (and vice versa).

Fortunately, you can view an obvious repeatable URL connection between the two sets of documentation. As long as this V1.1 command URL match directly reflects the parallel function, you can use simple approaches for redirecting to the corresponding pages. However, considering the number of deprecated V1.1 commands and other syntax V2.0 changes, the ultimate solution seems to require some type of lookup table. The techniques I discuss here won’t solve the ultimate problem but they represent a good starting point.

Matching the Web Page URLs

When you inspect the matching pages in AutoHotkey V1.1 and V2.0, you’ll note that most V1.1 command URLs include the same Web page name for the parallel V2.0 function. Other than that specific page name, the remainder of the URL changes to an alternative path.

V2URL
Everything except the name of the specific page changes when comparing V1.1 documentation with V2.0 documentation.

Examining the URLs of both the V1.1 page and the V2.0 page shows that each uses a common HTML page (e.g. ClipWait.htm). This makes it possible to jump to the corresponding page by replacing all but the page name.

Using Clipboard Techniques to Redirect Web Pages

I use the Standard AutoHotkey Clipboard Routine in this new script—as I did in the original AutoHotkey Quick Reference script. Each of these routines starts with selecting text by highlighting it by holding down the left mouse button while dragging across the unique Web page name.

Highlight Only the Web Page Name

The first technique involves selecting that unique portion of the page address (the page name) in the address bar of your Web browser to create the target URL. After navigating to an AutoHotkey V1.1 page, highlight the name of that HTML page (e.g. ClipWait) in your browser address field.

Ver2Redirect
Select the unique text in the address field of your Web browser,

After executing CTRL+ALT+V (^!v), the following routine copies the Web page name then includes it in the new URL:

^!v::
  OldClipboard := ClipboardAll
  Clipboard := "" ;clears the Clipboard
  SendInput ^c
  ClipWait 0 ;pause for Clipboard data
  If ErrorLevel
  {
    MsgBox, No text selected!
  }
  SendInput ^a
  SendInput https://lexikos.github.io/v2/docs/commands/%Clipboard%.htm`r
  Clipboard := OldClipboard
Return

This form of the Web page redirect creates a new URL using only the unique name of the page. Note the use of the escaped RETURN (`r) to initiate a new browser search.

Ver2Redirect2
The script changes the Web address to the new URL and inserts the RETURN (`r) to load the new page.

While this works, it takes a few more clicks than necessary. Perhaps we can make it a little easier.

Highlight the Entire Web Page Address

Most Web browsers automatically highlight the entire address bar when you click in the field. By taking advantage of this browser feature and using the StrReplace() function, we can eliminate the need to select the unique page name inside the address:

^!2::
  OldClipboard := ClipboardAll
  Clipboard := "" ; clears the Clipboard
  SendInput ^c
  ClipWait 0 ;pause for Clipboard data
  If ErrorLevel
  {
    MsgBox, No text selected!
  }

  Clipboard := StrReplace(Clipboard,"https://autohotkey.com/docs/commands/"
         ,"https://lexikos.github.io/v2/docs/commands/")
  SendInput %Clipboard%`r
  Clipboard := OldClipboard
Return

We still need the RETURN (`r) to launch the new search.

Launch Matching Page in a New Web Browser Tab

If you would prefer to launch the parallel V2.0 function pages in a new window, then replace the SendInput command with the Run command:

^!3::
  OldClipboard := ClipboardAll
  Clipboard := "" ; clears the Clipboard
  SendInput ^c
  ClipWait 0 ;pause for Clipboard data
  If ErrorLevel
  {
    MsgBox, No text selected!
  }
  Clipboard := StrReplace(Clipboard,"https://autohotkey.com/docs/commands/"
        , "https://lexikos.github.io/v2/docs/commands/")
  Run %Clipboard%
  Clipboard := OldClipboard
Return

This eliminates the need for the RETURN (`r) thus opening a new window or tab before launching the V2.0 page.

Launch the Page from Anywhere

Since the URL path never changes, you can eliminate the StrReplace() function and build the URL from any source where you can highlight text.

Plus, the Run command allows you to launch the code from anywhere without previously loading the browser or navigating to the V1.1 page. However, you must use the correct name of the page:

^!4::
 OldClipboard := ClipboardAll
 Clipboard := "" ; clears the Clipboard
 SendInput ^c
 ClipWait 0 ;pause for Clipboard data
 If ErrorLevel
 {
 MsgBox, No text selected!
 }
 Clipboard := "https://lexikos.github.io/v2/docs/commands/" 
    . Clipboard . ".htm"
 Run %Clipboard%
 Clipboard := OldClipboard
Return

On the downside, not only you must you remember the exact command name, it won’t work for many variations. For example, for the Send command, the appropriate parallel page loads. However, since it uses the same reference Send.htm page, the SendInput command does not load the appropriate page.

Time for a lookup table.

jack

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s