Save clipboard to file (Windows VBS)

script

Originally posted as GitHub Gist on 17 Aug 2017 (details)


Source: https://gist.github.com/paulera/b9af6f44aa553b6063d928547c26eab9

Description: VBScript to save clipboard contents to a text file.


ClipboadToFile.vbs

Option Explicit
 
' Gets clipboard's contents as pure text and saves it
' to the file set in filePath variable.
' author https://github.com/paulera
' see https://gist.github.com/paulera/b9af6f44aa553b6063d928547c26eab9

' File path to save clipboard contents
Dim filePath : filePath = "C:\clipboard.txt"

' Use the HTML parser to have access to the clipboard and get text content
Dim text : text = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")

' Create the file
Dim fileObj : Set fileObj = CreateObject("Scripting.FileSystemObject").CreateTextFile(filePath)

' Overwrite the text and close the file.
fileObj.Write(text)
fileObj.Close