← Back to Blog

Developers & Code | Published Oct 5, 2026 | Updated Oct 13, 2026 | 6 min read

AutoHotkey v2 Clipboard Scripts: 5 Copy-Paste Examples

By Deepender Yadav

AutoHotkey v2 Clipboard Scripts: 5 Copy-Paste Examples — Edge Drop Guide

AutoHotkey v2 controls the Windows clipboard through a few built-ins: A_Clipboard reads and writes clipboard text, ClipboardAll() saves and restores everything on it, ClipWait waits for a copy to arrive, and OnClipboardChange runs a function every time the clipboard changes. The five scripts below use them to paste as plain text, append to the clipboard, clean links as you copy, pick from a clipboard history menu, and log every copy to a file.

Every script is written for AutoHotkey v2 and starts with #Requires AutoHotkey v2.0, so it stops with a clear message if you run it with v1. Old v1 scripts from forums won't run unchanged in v2.

The clipboard built-ins in AutoHotkey v2

Built-inWhat it does
A_ClipboardThe clipboard's contents as text. Assign to it to set the clipboard, assign "" to empty it.
A_Clipboard := A_ClipboardConverts whatever is on the clipboard (HTML, rich text, copied files) to plain text.
ClipboardAll()Saves every format on the clipboard. Assign the result back to A_Clipboard to restore it.
ClipWait(Timeout)Waits until the clipboard contains text (or files). Returns false if it times out.
OnClipboardChange(Func)Calls Func on every clipboard change. Its parameter is 0 for empty, 1 for text or files, 2 for other data such as images.

To run a script, install AutoHotkey v2, save the code as a .ahk file, and double-click it. Its green "H" icon appears in the notification area; right-click it to reload or exit. Put several scripts in one file if you like, but keep only one #Requires line at the top.

Script 1: Paste as plain text with Ctrl+Shift+Alt+V

This converts the clipboard to plain text, pastes it, then puts the original formatted contents back, so nothing is lost.

#Requires AutoHotkey v2.0

^+!v:: {
    saved := ClipboardAll()      ; keep every format of the current clipboard
    A_Clipboard := A_Clipboard   ; reduce it to plain text
    Send "^v"                    ; paste
    Sleep 250                    ; give the target app time to read the clipboard
    A_Clipboard := saved         ; restore the original
    saved := ""                  ; free the memory
}

It works in any app that accepts Ctrl+V, including ones without a "paste as plain text" option. If the clipboard holds an image rather than text, the paste is empty and the image is restored afterwards. If a slow app pastes the formatted version, raise the Sleep value. How to paste without formatting on Windows lists the built-in alternatives.

Script 2: Append the selection to the clipboard

Normally each copy replaces the last one. This hotkey adds the selected text to the end of what's already on the clipboard, separated by a line break, so you can collect several passages and paste them once.

#Requires AutoHotkey v2.0

^+!c:: {
    previous := A_Clipboard
    A_Clipboard := ""            ; empty it so ClipWait can detect the new copy
    Send "^c"
    if !ClipWait(1) {            ; nothing arrived within one second
        A_Clipboard := previous
        return
    }
    if (previous != "")
        A_Clipboard := previous "`r`n" A_Clipboard
}

Emptying the clipboard before sending Ctrl+C matters. Without it, ClipWait returns immediately because the old text is still there, and you'd append the previous clip to itself.

Ctrl+Shift+Alt+C was chosen to avoid common shortcuts such as Ctrl+Shift+C, which opens the element picker in Chrome and Edge DevTools. A hotkey in AutoHotkey overrides the same shortcut in every app, so pick a combination you don't use elsewhere.

Script 3: Remove tracking parameters from links as you copy

This runs on every copy. When the clipboard holds a single web address, it strips utm_ tracking parameters and trims stray spaces; anything else is left alone.

#Requires AutoHotkey v2.0

OnClipboardChange(CleanLink)

CleanLink(DataType) {
    if (DataType != 1)                                   ; text only
        return
    if DllCall("IsClipboardFormatAvailable", "UInt", 15) ; CF_HDROP: files copied in Explorer
        return
    text := Trim(A_Clipboard)
    if !RegExMatch(text, "^https?://\S+
quot;) ; only a single URL return clean := RegExReplace(text, "(?<=[?&])utm_[^&#]*&?", "") clean := RegExReplace(clean, "[?&](?=#|$)", "") if (clean !== A_Clipboard) A_Clipboard := clean }

Setting the clipboard from inside the callback triggers the callback again. That second run finds nothing left to clean, so the clean !== A_Clipboard check stops it from writing a second time. The check for format 15 (CF_HDROP) makes sure files copied in File Explorer are never turned into text.

Because the script replaces the clipboard with plain text, a copied link loses any rich formatting. Extend the second pattern to strip other parameters you see often, such as fbclid. How to copy a clean link without tracking parameters covers the manual and browser options.

Script 4: A clipboard history menu on Ctrl+Alt+H

This keeps your last 20 text copies in memory and shows them as a menu at the mouse pointer. Click an entry to paste it.

#Requires AutoHotkey v2.0

history := []
maxItems := 20
OnClipboardChange(SaveClip)

SaveClip(DataType) {
    if (DataType != 1)
        return
    text := A_Clipboard
    if (text = "")
        return
    for i, item in history {         ; move a repeat to the top instead of duplicating it
        if (item == text) {
            history.RemoveAt(i)
            break
        }
    }
    history.InsertAt(1, text)
    if (history.Length > maxItems)
        history.Pop()
}

^!h:: {
    if (history.Length = 0) {
        ToolTip "Clipboard history is empty"
        SetTimer () => ToolTip(), -1500
        return
    }
    target := WinExist("A")                  ; remember the window to paste into
    m := Menu()
    for i, text in history {
        label := SubStr(RegExReplace(text, "\s+", " "), 1, 60)
        label := StrReplace(label, "&", "&&")   ; show & literally in the menu
        m.Add(i ". " label, PasteItem.Bind(text, target))
    }
    m.Show()
}

PasteItem(text, target, *) {
    A_Clipboard := text
    if WinExist(target)
        WinActivate(target)
    Send "^v"
}

The history lives only in memory, so it's gone when the script exits or the PC restarts. It holds text only: no images, no search and no pinning. That's where a dedicated manager earns its place; Ditto vs CopyQ compares the two most popular free ones.

Script 5: Log every text copy to a file

For research sessions where you need a record of what you copied and when, this appends each text copy to a dated log in your Documents folder.

#Requires AutoHotkey v2.0

OnClipboardChange(LogClip)

LogClip(DataType) {
    if (DataType != 1)
        return
    stamp := FormatTime(, "yyyy-MM-dd HH:mm:ss")
    FileAppend(stamp " | " A_Clipboard "`r`n", A_MyDocuments "\clipboard-log.txt", "UTF-8")
}

The log is a plain text file holding everything you copy, including any password or token you copy while the script runs. Exit the script before handling secrets, and delete the file when the session is over. How to pause clipboard capture when you're copying secrets has the wider checklist.

Common mistakes in clipboard scripts

  • Not emptying the clipboard before a scripted copy. Set A_Clipboard := "" before Send "^c", then call ClipWait with a timeout. Otherwise the script may read the old contents.
  • Calling ClipWait without a timeout. With no timeout it waits forever if nothing is selected. ClipWait(1) waits one second.
  • Callbacks that change the clipboard every time. Writing to A_Clipboard inside an OnClipboardChange function triggers it again. Only write when the value actually changes, as Script 3 does.
  • Restoring the clipboard too soon. Some apps read the clipboard a moment after Ctrl+V. If pastes come out wrong, increase the Sleep before restoring.

AutoHotkey or a clipboard manager?

Use AutoHotkey for transformations you do over and over: paste as plain text, clean links, append, reformat. A script does exactly what you write and nothing else.

Use a clipboard manager for retrieval: searching last week's copies, previewing images, pinning snippets you reuse. Ditto and CopyQ are free and keyboard-driven, and both keep history across restarts.

They can run together, but avoid having two programs rewrite the clipboard on every copy, or they may react to each other's changes. Can you run two clipboard tools at once? covers what conflicts and what doesn't. If you'd rather script the clipboard from a terminal, see the PowerShell clipboard cheat sheet; for a no-code route, Power Automate Desktop's clipboard actions handle similar cleanup in a visual flow.

FAQ

Do these scripts work with AutoHotkey v1?

No. They use v2 syntax such as A_Clipboard, ClipWait(1) and fat-arrow functions. The #Requires AutoHotkey v2.0 line makes AutoHotkey v1 stop with an error instead of running them.

How do I start a script automatically when Windows starts?

Put a shortcut to the .ahk file in your Startup folder. Press Win+R, type shell:startup, and press Enter to open it.

Can AutoHotkey save images from the clipboard?

ClipboardAll() can save and restore all clipboard formats, including images, to a variable or a file. Turning a clipboard image into a PNG file needs extra code or a library.

Related reading

Sources

Deepender Yadav
Written by Deepender Yadav · Creator & Developer

Deepender Yadav created Edge Drop and builds and tests it, from the edge-hover shelf to each release. A B.Tech Computer Science Engineering student, Deepender writes the Edge Drop guides, comparisons and developer posts, and checks product details against the app's source code.

GitHub · LinkedIn

Copy. Stack. Drop.

Transform your clipboard into an interactive edge shelf. Stack, pin, and drag assets into any app with zero friction.

Download for Windows Get from Microsoft Store

How to Install Guide · First 10 Minutes Guide · Drag & Drop Guide · Edge Drop vs Win+V · Support

Free · Lightweight · Privacy First
Find us on CodeHype