A_Clipboard

A_Clipboard is a built-in variable that reflects the current contents of the Windows clipboard if those contents can be expressed as text.

Each line of text on A_Clipboard typically ends with carriage return and linefeed (CR+LF), which can be expressed in the script as `r`n. Files (such as those copied from an open Explorer window via Control+C) are considered to be text: They are automatically converted to their filenames (with full path) whenever A_Clipboard is referenced in the script. To extract the files one by one, follow this example:

Loop Parse A_Clipboard, "`n", "`r"
{
    Result := MsgBox("File number " A_Index " is " A_LoopField ".`n`nContinue?",, 4)
    if Result = "No"
        break
}

To arrange the filenames in alphabetical order, use the Sort function. To write the filenames on the clipboard to a file, use FileAppend A_Clipboard "`r`n", "C:\My File.txt". To change how long the script will keep trying to open the clipboard -- such as when it is in use by another application -- use #ClipboardTimeout.

ClipWait may be used to detect when the clipboard contains data (optionally including non-text data):

A_Clipboard := ""  ; Start off empty to allow ClipWait to detect when the text has arrived.
Send "^c"
ClipWait  ; Wait for the clipboard to contain text.
MsgBox "Control-C copied the following contents to the clipboard:`n`n" A_Clipboard

Related

Examples

#1

A_Clipboard := "my text"   ; Give the clipboard entirely new contents.
A_Clipboard := ""  ; Empty the clipboard.
A_Clipboard := A_Clipboard   ; Convert any copied files, HTML, or other formatted text to plain text.
A_Clipboard .= " Text to append."   ; Append some text to the clipboard.
A_Clipboard := StrReplace(A_Clipboard, "ABC", "DEF")   ; Replace all occurrences of ABC with DEF (also converts the clipboard to plain text).

Clipboard utilities written in AutoHotkey v1: