Windows utility/tool command line to move clipboard to file
Windows cmd
(if clipboard contains text data):
Powershell -command Add-Type -AssemblyName System.Windows.Forms;[System.Windows.Forms.Clipboard]::GetText()
Example shows that above command adds two bytes to output (Cr and Lf):
==> >1049363a.txt echo first line
==> >>1049363a.txt echo 2nd line
==> clip<1049363a.txt
==> >1049363b.txt Powershell -command Add-Type -AssemblyName System.Windows.Forms;[System.W
indows.Forms.Clipboard]::GetText()
==> findstr /N "^" 1049363*.txt
1049363a.txt:1:first line
1049363a.txt:2:2nd line
1049363b.txt:1:first line
1049363b.txt:2:2nd line
1049363b.txt:3:
==> dir 1049363*.txt |find ".txt"
06.03.2016 17:24 22 1049363a.txt
06.03.2016 17:24 24 1049363b.txt
==>
Read more about .NET Framework Clipboard Class methods.
Edit answers extended topic (save image, cf. ImageFormat Class):
Add-Type -AssemblyName System.Windows.Forms ### not necessary in PowerShell_ISE
if ($([System.Windows.Forms.Clipboard]::ContainsImage())) {
$image = [System.Windows.Forms.Clipboard]::GetImage()
$filename='d:\test\test.png' ### edit to fit in your circumstances
[System.Drawing.Bitmap]$image.Save($filename,
[System.Drawing.Imaging.ImageFormat]::Png)
Write-Output "clipboard content saved as $filename"
} else {
Write-Output "clipboard does not contains image data"
}
You can use the PowerShell cmdlet Get-Clipboard
(aliased as gcb
).
Write clipboard text to a file:
gcb > myfile.txt
It does have an option for getting an image from the clipboard, -Format Image
, but that seems to only provide meta data, so it may not be helpful in writing an image to a file.
Does anybody have tool that works from clipboard to file?
This can done using a batch file containing some embedded VBS.
GetClip.cmd:
@echo off
(
echo set objHTML = CreateObject("htmlfile"^)
echo ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text"^)
echo set objFSO = CreateObject("Scripting.FileSystemObject"^)
echo set objFile = objFSO.OpenTextFile("clip.txt", 2, true^)
echo objFile.WriteLine ClipboardText
echo objFile.Close
) > "%temp%\clip.vbs"
"%temp%\clip.vbs"
endlocal
Notes:
- Clipboard contents are written to
clip.txt
in the current directory
Example Usage:
F:\test>type LoremIpsum.txt
Id pri magna tibique, vel et eruditi perpetua, numquam mandamus sed et.
Te nam diam veritus.
Ad est quaestio ocurreret, at vix modo prima officiis.
Modus principes definiebas mei et, atqui exerci ea sit.
An eirmod saperet dissentiunt sea, esse postea eleifend ex eam.
F:\test>clip<LoremIpsum.txt
F:\test>getclip
F:\test>type clip.txt
Id pri magna tibique, vel et eruditi perpetua, numquam mandamus sed et.
Te nam diam veritus.
Ad est quaestio ocurreret, at vix modo prima officiis.
Modus principes definiebas mei et, atqui exerci ea sit.
An eirmod saperet dissentiunt sea, esse postea eleifend ex eam.
F:\test>
Source: Based on Batch code to paste from clipboard to a file?