Open and Print Files with the QuickLinks App (AutoHotkey Tip from a Reader)

Khanh Ngo Offers an Improvement to the QuickLinks.ahk Script Which Enables the Loading of Any Selected File with Your Favorite Program, Plus QuickLinks Can Now Print Files!

Recently I received the following message:

Hi, Jack,

Library Benefits

I just found your website when searching around for AHK tips and found your QuickLinks—very impressive, with minimal coding needed.

I’m currently making good use of it and added a small improvement to QL_MenuHandler that I think you might appreciate too:

When executing a shortcut, send currently selected files as an argument to that program. Basically, open the selected file with the QuickLinks program.

This is quite convenient when opening a text or image editor.

Let me know what you think.

Khanh

After reviewing the changes to the QuickLinks.ahk script, I saw that with the short piece of code, Khanh had greatly expanded the possibilities. What started out as a tool for quickly opening favorite programs and Web pages turned into a method for opening any file with those same preferred applications. I immediately incorporated the new code in the current download.

Open Any File with Your Favorite Software

I don’t know why I didn’t think of it, but Khanh’s addition to the script blew my mind for both its simplicity and power. This straightforward innovation in the code propelled the QuickLinks.ahk script into the dynamic tools category. Not only does QuickLinks open your favorite programs, folders, and Web pages, but now you can instantly open any file with any program listed in your QuickLinks menu without any tedious searches. Just select the filename in Windows File Explorer, open your QuickLinks menu with a click of that special button (XButton1) on your mouse (or a Hotkey combination) and pick the target program. The program loads as usual but now the file opens in the new window.

The new code inserted into the QL_MenuHandler subroutine appears in red as follows:

QL_MenuHandler:
If A_ThisMenuItem contains Windows Tools
   {
	 Run
         , "C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\Windows Tools
         .{ED7BA470-8E54-465E-825C-99712043E01C}"
   } 
Else
  {
  IfExist
    , C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.url
    Run
    , C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.url
  Else  
    { 
    Clip0 := ClipboardAll     ; Backup current clipboard's content
    Clipboard :=              ; Clear clipboard
    SendInput, ^c             ; Copy selected file's path to clipboard
    ClipWait 0                ; Waits ½ second for clipboard to load
    IfExist, %Clipboard%
      {
        Run
        , C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%
        .lnk "%clipboard%"
       }
     Else
       {
       Run
         , C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%
         .lnk
       }

     Clipboard := Clip0           ; Restore original ClipBoard
     VarSetCapacity(Clip0, 0)      ; Free memory
     }
 }
Return

(A number of the lines above word wrap for display purposes using AutoHotkey line continuation techniques. To see them as one continous line, check out the QuickLinks.ahk script located on the “ComputorEdge Free AutoHotkey Scripts and Apps” page.)

The above code takes advantage of the Windows Clipboard by copying the selected filename (CTRL+C or SendInput, ^c) after first saving its current contents (Clip0 := ClipboardAll) and clearing the Clipboard (Clipboard :=).

If the file path and name exists in the Clipboard (IfExist, %Clipboard%), AutoHotkey uses that file as an argument when launching the shortcut from the QuickLinks menu. If not, the program loads normally displaying an empty window. No need to make any changes to any of your shortcuts.

Printing with QuickLinks

This new addition to QuickLinks.ahk further inspired me to ask, “If I can open files with QuickLinks, why not print them?” In many cases, you can!

Any program which accepts print command line parameters (e.g. Notepad /p) can act as a print server. You only need to open the properties windows (right-click on the shortcut icon in your QuickLinks subfolder and select properties) and add the appropriate parameter to the Target line. See image below.

Shortcut Print Properties Window
For Notepad, add the print argument to the Target path (e.g. /P). When the selected text file loads, Notepad automatically prints it.

Not all programs accept command line parameters. Only those applications capable of printing from the Command Prompt function with this technique. Plus, the parameter must precede the newly insert filename. For example, while many programs require the placement of /p prior to the filename, some look for the argument to follow the target filename. IrfanView image viewer places the parameter /print after the filename which breaks the scheme. To make this Irfanview formatting operational would require special coding (which we would like to avoid). For more information on using programs to print through AutoHotkey, see “Printing with AutoHotkey Made Simple).”

PrintMenu

I  recommend changing the new shortcut name to something including the word Print (as shown at right). Then, place all the shortcuts in a separate folder specifically for printing different types of files (e.g. Print Files). This way they won’t get confused with the regular program shortcuts for opening files.

If you need to print graphics files, you will likely want to find something better than Microsoft Paint. It always expands the image to fit the page. You may find it easier to just open an image in one of the paint-type programs, then print it.

Adding Web Queries to QuickLinks

I understand that Khanh plans to add Web queries to the QuickLinks.ahk script. I would guess that the solution will involve a combination capturing the search terms with the Windows Clipboard techniques just used for loading selected files and inserting modified URLs into shortcuts with steps similar to how we added the program command line parameters for printing. This would tack-on Web search capabilities to QuickLinks which might include Google, dictionaries, thesauruses, food calories, and any other available Web data.

We may see that soon.

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

One thought on “Open and Print Files with the QuickLinks App (AutoHotkey Tip from a Reader)

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 )

Facebook photo

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

Connecting to %s