<

How to copy the short link of an ID at Experts Exchange to the clipboard with a single keystroke

Published on
24,982 Points
1,982 Views
5 Endorsements
Last Modified:
Approved
Joe Winograd
50+ years in computer industry •Everything from development to sales •CIO •Windows •Document Imaging •EE MVE 2015,2016,2018 •EE FELLOW 2017
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a technique for doing this with a single keystroke.

Each comment in Question threads here at Experts Exchange has a unique Identifier (ID). The full path of the link for an ID looks like this:


https://www.experts-exchange.com/questions/12345678/Title-of-this-question.html#a87654321


It is easy to copy that full path to the clipboard by right-clicking on it and then selecting the appropriate context menu item in your browser. For example, in Chrome, Opera, and Vivaldi, the menu item is Copy link address; in Firefox, it is Copy Link Location; in IE11, Copy shortcut. However, we often want to post a short link within a thread, rather than the full link. The short link is everything after and including the number symbol (aka hash, octothorpe, pound sign), such as:


#a87654321


An EE member recently posted a bug report pointing out that it is difficult to get the short link. He noted that a cumbersome, manual technique is to copy non-clickable text surrounding and including it, cleaning it up, and adding the pound sign, thereby creating the short link. Another technique, also manual and cumbersome, is to copy the full path, then delete everything before the short link. This article shows an easy, automated method for obtaining the short link with a single keystroke.


The primary component that we'll need for the solution is a scripting language that supports the Windows clipboard, and sending mouse clicks and keystrokes. In this article, I'll explain how to do it with AutoHotkey, my favorite programming/scripting language these days — but pick whatever language with which you're comfortable. If you'd like to learn about AutoHotkey, this EE article will get you going:


AutoHotkey - Getting Started


The method offered here is to position the mouse on the ID of interest and then tap a hotkey, which can be any key or key combination that you want, such as F5, NumPad+, Alt-Ctrl-I, whatever. Here's the AutoHotkey script for use with Firefox, containing ample comments so that it's easy to understand its operation:


F5::                               ; use F5 as hotkey

Clipboard:=""                      ; empty the clipboard

MouseClick,Right                   ; right-click at current mouse location

Sleep,60                           ; wait for 60 milliseconds to make sure context menu is there

SendInput a                        ; send letter "a", the Firefox shortcut for Copy Link Location

ClipWait,2                         ; wait at most two seconds for short link to appear in clipboard

If (ErrorLevel=1)                  ; ErrorLevel set to 1 when wait period expires

{

  MsgBox,4112,Error,Attempt to copy the short link onto the clipboard failed.

  Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon

}

StringSplit,ShortLink,Clipboard,#  ; split long link into two strings, separated at pound sign

ShortLink:="#" . ShortLink2        ; add pound sign to second string, creating the short link

Clipboard:=ShortLink               ; put short link on clipboard

Return                             ; success


As you can see in the code above, if the short link does not appear on the clipboard within two seconds, the script displays this error dialog:


The "SendInput a" in the script works because the Firefox keyboard shortcut for Copy Link Location is "a". However, in Chrome, the keyboard shortcut for Copy Link Address is "e", so that line in the script should be changed to this:

 

SendInput e                        ; send letter "e", the Chrome shortcut for Copy Link Address


If the browser that you are using doesn't have a keyboard shortcut for the menu pick that copies the link to the clipboard (such as "a" and "e" in the examples above), then you can navigate through the context menu with the down arrow as many times as needed to get to that item, and then send the Enter key. For example, in Chrome, it takes five down-arrows to get to the Copy Link Address menu pick. So you would replace "SendInput e" in the script with this:

 

SendInput {Down 5}{Enter}          ; send five down arrows then the Enter key


Many users stick to a single browser, but if you use multiple browsers, an enhanced version of the script will support them. For example, here's a script that detects whether Chrome, Firefox, IE, or Opera is running and sends the correct keystroke(s) for each:

F5:: WinGetTitle,ActiveTitle,A                 ; get title of active window IfInString,ActiveTitle,Mozilla Firefox    ; check if active window is Firefox   ShortcutKey:="a"                        ; send letter "a", Firefox shortcut for Copy Link Location Else                                      ; it is not Firefox IfInString,ActiveTitle,Google Chrome      ; check if active window is Chrome   ShortcutKey:="e"                        ; send letter "e", Chrome shortcut for Copy Link Address Else                                      ; it is not Chrome IfInString,ActiveTitle,Internet Explorer  ; check if active window is IE   ShortcutKey:="t{Enter}"                 ; send letter "t", IE shortcut for Copy Shortcut, but also needs Enter Else                                      ; it is not IE IfInString,ActiveTitle,Opera              ; check if active window is Opera   ShortcutKey:="e"                        ; send letter "e", Opera shortcut for Copy Link Address Else                                      ; it is not Opera {   MsgBox,4112,Error,Active window is not a supported browser.   Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon } Clipboard:=""                             ; empty the clipboard MouseClick,Right                          ; right-click at current mouse location Sleep,60                                  ; wait for 60 milliseconds to make sure context menu is there SendInput,%ShortcutKey%                   ; send shortcut to copy link ClipWait,2                                ; wait at most 2 seconds for short link to appear in clipboard If (ErrorLevel=1)                         ; ErrorLevel set to 1 when wait period expires {   MsgBox,4112,Error,Attempt to copy the short link onto the clipboard failed.   Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon } StringSplit,ShortLink,Clipboard,#         ; split long link into two strings, separated at pound sign ShortLink:="#" . ShortLink2               ; add back pound sign to short link Clipboard:=ShortLink                      ; put short link on clipboard Return                                    ; success


This script works by looking at the title bar of the active window to see if it contains Mozilla Firefox, Google Chrome, Internet Explorer, or Opera. If it doesn't find one of those, it displays this error dialog:



There are two issues with the approach used in this script. First, a window title could contain one of those strings even if that browser is not running, e.g., if you are viewing a file called Mozilla Firefox ReadMe.txt in Notepad. Second, some browsers do not put the browser name in the window title, such as Vivaldi. To solve those issues, the script could use the ahk_exe parameter on the WinGetTitle statement, which identifies a window belonging to any process with the specified name or path, such as chrome.exe, firefox.exe, iexplore.exe, opera.exe, vivaldi.exe. I'll leave the creation of such a script to motivated readers. :)


In conclusion, after positioning the mouse on an EE comment ID and hitting the hotkey that you have defined, you will have the short link on the clipboard — simply do a Ctrl-V/Paste to put it wherever you want!


If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

5
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free