Windows utility/tool command line to move clipboard to file

I have seen a similar tool CLIP here Clip command but it works into clipboard not the other direction.

I have seen references to "paste" but this doesnt appear to be part of windows. I need to find a solution that works with standard w7 w8 w10 environments.

Clip is distributed. Does anybody a tool that works from clipboard to file?

EDIT Seems it might be possible to do with a powershell command
This C# program I just wrote does what I would to do with a Powershell

class Clip2File
{
    [STAThread()]
    static void Main(string[] args)
    {
        var fileName = @"c:\demo.png";
        if (args.Length != 0){
            fileName = args[0];
        }
        if (!Clipboard.ContainsImage()) return;
        Image img = Clipboard.GetImage();
        img?.Save(fileName, ImageFormat.Png);
    }
}

Solution 1:

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"
}

Solution 2:

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.

Solution 3:

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?

Solution 4:

Best way I know, is by using a standalone tool called WINCLIP .

You can get it from here: Outwit

Usage:

  • Save clipboard to file: winclip -p file.txt

  • Copy stdout to clipboard: winclip -c Ex: Sed 's/find/replace/' file | winclip -c

  • Pipe clipboard to sed: winclip -p | Sed 's/find/replace/'

  • Use winclip output (clipboard) as an argument of another command:

    FOR /F "tokens=* usebackq" %%G in ('winclip -p') Do (YOUR_Command %%G )

You might also want to take a look at getclip & putclip tools: CygUtils for Windows but winclip is better in my opinion.