Modify hotkey replacement code to also include link replacement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Modify hotkey replacement code to also include link replacement

Post by milkygirl90 » 31 Jul 2021, 17:35

This is the current hotkey replacement script I'm using. How do I modify it such that it can also:

1. Accept full links without any need for wildcards such as

Code: Select all

https://www.autohotkey.com/boards/posting.php?mode=post&f=76
2. Accept full links that have 1, 2 or 3 wildcards:

Code: Select all

https://www.autohotkey.com/boards/search.php?keywords=%s ; %s is the wildcard
https://encrypted.google.com/search?num=40&safe=off&hl=en&biw=1536&bih=783&q=%s+USD+to+GBP ; %s is first wildcard for numbers, USD and GBP are 2ⁿᵈ and 3ʳᵈ wildcard inputs
3. Most importantly, how do I get the script to give me options to overwrite and amend its existing code, OR tell me to give a new hotkey if this hotkey already exists?

Thank you!

Code: Select all

#h::  ; Win+H hotkey ;Creates hotkey based on selected text
AutoTrim Off  ; Retain any leading and trailing whitespace on the clipboard.
;ClipboardOld = %ClipboardAll%
Clipboard =  ; Must start off blank for detection to work.
SendInput ^+{Left} ;select word on left
Send ^c
ClipWait 1
if ErrorLevel  ; ClipWait timed out.
    return
; Replace CRLF and/or LF with `n for use in a "send-raw" hotstring:
; The same is done for any other characters that might otherwise be a problem in raw mode:
StringReplace, Hotstring, Clipboard, ``, ````, All  ; Do this replacement first to avoid interfering with the others below.
StringReplace, Hotstring, Hotstring, `r`n, ``r, All  ; Using `r works better than `n in MS Word, etc.
StringReplace, Hotstring, Hotstring, `n, ``r, All
StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
StringReplace, Hotstring, Hotstring, `;, ```;, All
;Clipboard = %ClipboardOld%  ; Restore previous contents of clipboard.
; This will move the InputBox's caret to a more friendly position:
SetTimer, MoveCaret, 10
; Show the InputBox, providing the default hotstring:
InputBox, Hotstring, New Hotstring, Type your abreviation at the indicated insertion point. You can also edit the replacement text if you wish.`n`nExample entry: :R:btw`::by the way,,,,,,,, :R:`::%Hotstring%
if ErrorLevel  ; The user pressed Cancel.
    return
IfInString, Hotstring, :R:`:::
{
    MsgBox You didn't provide an abbreviation. The hotstring has not been added.
    return
}
; Otherwise, add the hotstring and reload the script:
FileAppend, `n%Hotstring%, %A_ScriptFullPath%  ; Put a `n at the beginning in case file lacks a blank line at its end.
Reload
Sleep 200 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
MsgBox, 4,, The hotstring just added appears to be improperly formatted.  Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
IfMsgBox, Yes, Edit
return

MoveCaret:
IfWinNotActive, New Hotstring
    return
; Otherwise, move the InputBox's insertion point to where the user will type the abbreviation.
Send {Home}{Right 3}
SetTimer, MoveCaret, Off
return


Image
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Modify hotkey replacement code to also include link replacement

Post by milkygirl90 » 03 Aug 2021, 21:55

Any advice please? Thank you.
Post Reply

Return to “Ask for Help (v1)”