Content awareness of AutoHotKey script

autohotkey scripts
autohotkey run file in specific program
run autohotkey script on startup
autohotkey open selected file with specific program
autohotkey open program
how to open ahk files
ahk run example
open a file autohotkey

Is there a content awareness feature of AutoHotKey? I need to replace some selected text in my application. Imagine the following CSHTML:

@
{
    ViewBag.Title = "Welcome";
}

<p>Welcome to this page</p>

I have created a very simple script, that (once text has been selected):

  1. Clears clipboard
  2. Send CTRL+C
  3. Send @normalize("
  4. Send CTRL+V
  5. Send ")

That means, that if I select Welcome to this page, it will be replaced with @normalize("Welcome to this page"). That part works perfectly fine.

However, if I want to replace "Welcome" with the same, I would have to select the quotation marks, which speeds down this automation script quite a lot, because I can't simply double click on the word and select it. Now I would have to press and hold, then drag the mouse across the screen until it reaches the last ending quotation mark.

Instead, I need my AutoHotKey script to do something like:

Send CTRL + C;
var caret = currentCaretTextPosition; //made up
IF caret+1 IS "
    Send Delete
IF caret-1 IS "
    Send Backspace
Send @normalize("
Send CTRL+V
Send ")

If that makes sense. Basically transforms "Welcome" into:

  1. ""
  2. "
  3.  
  4. @normalize("
  5. @normalize("Welcome
  6. @normalize("Welcome")

This is very basic content awareness stuff, because it checks the surrounding characters of the caret, then acts upon that.

AutoHotKey script (triggered by CTRL+ALT+SHIFT+X):

^!+x::
clipboard:=""
While clipboard
Sleep 10
While !clipboard
{
    Send ^c
    Sleep 100
}
Sleep 20
Send @normalize("
Sleep 20
Send ^v
Sleep 20
Send ")
return

This solution will check if there are surrounding quotes and proceed accordingly. It may fail if there is nothing to the right (such as end of file). It does stop if nothing is selected initially. It does not check if what is selected already contains quotes.

^!+x::
clipboard := ""
Send , ^x
ClipWait , 1
If ErrorLevel
    Return
sNormalize := clipboard
clipboard := ""
Send , {right}+{left 2}^c
ClipWait , 1
Send , % ( clipboard = """""" ? "{del}" : "{left}{right}" )
clipboard := "@normalize""" . sNormalize . """)"
Send , ^v
Return

Script to open selected file with specific program., Send, ^c ClipWait ;waits for the clipboard to have content Run, I am also not aware of the differences between the Unicode and ASCII� Each script is a plain text file containing lines to be executed by the program (AutoHotkey.exe). A script may also contain hotkeys and hotstrings, or even consist entirely of them. However, in the absence of hotkeys and hotstrings, a script will perform its commands sequentially from top to bottom the moment it is launched.

I've made a not-so-bulletproof fix, but it unfortunately requires me to use another keybinding, which I'm not a fan of:

^!+z::
clipboard:=""
While clipboard
Sleep 10
While !clipboard
{
    Send ^x
    Sleep 100
}
Sleep 20
Send {Right}
Sleep 5
Send {BackSpace}
Sleep 5
Send {BackSpace}
Send @normalize("
Sleep 20
Send ^v
Sleep 20
Send ")
return

It does what I wanted above, but it's not very bulletproof.

A Central Scripts repo would be great, I am aware of the scripts showcase and googling finds various stashs of scripts on reddit or Filtering out useless code and malicious content. This script watches while you edit an AutoHotkey script. When it sees you type a command followed by a comma or space, it displays that command's parameter list to guide you. In addition, you can press Ctrl+F1 (or another hotkey of your choice) to display that command's page in the help file. To dismiss the parameter list, press Escape or Enter.

Off topic but thought I'd mention it

If you have many of such snippets an alternative could be Lintalist, it is developed in AutoHotkey so you can extend it with your own scripts and plugins. The above script could be replaced with the following snippet - here it uses the selected text in your editor but you can use the clipboard as well:

@
{
    ViewBag.Title = "[[selected]]";
}

<p>[[selected]]</p>

You can group snippets in Bundles per application and/or language, assign hotkeys and search for them.

You can learn more about Lintalist here https://lintalist.github.io/ - available plugins here https://lintalist.github.io/#InteractiveBundleText

Will SysGet in v2 be per-monitor dpi aware?, My observation has been that some APIs use the scaling of whichever display the script's last active window was on (if it had any). That is not� This is very basic content awareness stuff, because it checks the surrounding characters of the caret, then acts upon that. AutoHotKey script (triggered by CTRL+ALT+SHIFT+X): ^!+x:: clipboard:="" While clipboard Sleep 10 While !clipboard { Send ^c Sleep 100 } Sleep 20 Send @normalize(" Sleep 20 Send ^v Sleep 20 Send ") return

Automatically executing script - Ask for Help, Automatically executing script - posted in Ask for Help: The general Atom, are you even aware of the auto-execute section of a AHK script? Supports drag'n'drop of images to upload them to Imgur. The script requries some pre-configuration before it can be used, so read the header in the script's code. StandDescription. A script that demonstrates the idea of dynamic GUI and saving/restoring data from an array or an object) into/from JSON format. StringyLauncher

A search dialogue to work on an edit control - Scripts , HugoV gave me a precious hint of how to find Laszlos script and heres the result. lastFind) { offset = 0 hits = 0 } GuiControl 1:Focus, Content ; focus on main I'm aware that I only played around with the excellent code of Testing the same script with 96 and 144 DPI the spacing is perfectly symetrical. The problem only occurs when using 120 DPI and are specifical visible between radiobuttons. Perhaps there is a bug in the AHK 120 DPI-awareness code? This is the script you can test with:

Beginner Tutorial, Table of Contents. The Basics. Downloading and installing AutoHotkey; How to create a script; You cannot merge commands; How to find the help file on your� It's no secret that we're huge fans of the simple but powerful AutoHotkey scripting language, and we use it religiously to automate Windows tasks and save time. Here's a handful of useful scripts

Comments
  • Very nice! Works just as I expected. Thank you
  • Hi again. Noticed that I forgot to mention, I still want the original copied string to be kept in the clipboard. For some reason, after I do the "Send , ^v" command, I cannot replace the clipboard variable with sNormalize. If I do that, sNormalize will get pasted instead of the new clipboard.
  • Hmmm, that's odd. Perhaps add something like, Sleep , 500 between?
  • Yeah I added a sleep and it works semi okay. 500 is a bit too much, so somewhere between 150 and 200 works flawlessly. Thanks again!