How to eliminate trailing space in AutoHotKey scripts

406 Views Asked by At

AutoHotKey v. 1.1.33.09. Windows 10, Firefox, Edge, Chrome, multiple applications

I have several lengthy email addresses associated with some non-profit work I do. I am creating shortcut keystrokes in an autohotkey script for each email address, phone number, and mailing address to speed form filling.

There are unwanted trailing single spaces being produced in the output string which forces me to manually type a backspace in order to move on in the form that is being filled.

How to elegantly eliminate these spaces?

::.1::[email protected]
return
::.2::[email protected]
return
::.ad::1234 Address Blvd, Anytown, USA 99999-1234
return
::.p::1-800-555-5555
return

note: In the examples below the underscore symbol _ represents an unwanted trailing space.

.1[enter] returns [email protected]_

.2[enter] returns [email protected]_

.ad[enter] returns 1234 Address Blvd, Anytown, USA 9999-1234_

.p[enter] returns 1-800-555-5555_

1

There are 1 best solutions below

5
On

The O option(docs) should do the trick for you:

O: Omit the ending character of auto-replace hotstrings when the replacement is produced. This is useful when you want a hotstring to be kept unambiguous by still requiring an ending character, but don't actually want the ending character to be shown on the screen. For example, if :o:ar::aristocrat is a hotstring, typing "ar" followed by the spacebar will produce "aristocrat" with no trailing space, which allows you to make the word plural or possessive without having to press Backspace. Use O0 (the letter O followed by a zero) to turn this option back off.

So your script would be:

:O:.1::[email protected]
:O:.2::[email protected]
:O:.ad::1234 Address Blvd, Anytown, USA 99999-1234
:O:.p::1-800-555-5555

Note that I also removed the redundant returns.
They're only needed if you're not writing one-liners.