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 Ctrl+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
Replaces all occurrences of ABC with DEF (also converts the clipboard to plain text).
A_Clipboard := StrReplace(A_Clipboard, "ABC", "DEF")
Clipboard utilities written in AutoHotkey v1: