Copy text contents from file to clipboard

I have text file - frequently modified - i want to create a button - when i click on it, this file will be copied to clipboard - i want paste this text to other application manually.

So - i need copy contents of file to clipboard.

Anyone help me?
I tried and i can't do this...

You can use my SetClip program to do this.

The page for it even has an example Opus toolbar button which should do exactly what you need:

[SetClip)

or

pretentiousname.com/miscsoft ... ml#SetClip

C:>d:\dane\PROGRAMY\TEKST\SetClip.exe -e

C:>d:\dane\PROGRAMY\TEKST\SetClip.exe -f -a k:\Fajne_teksty.txt
WARNING: Cannot append as no text data in the clipboard.

... and when i try to paste text in editor i get this:

"
˙ţA"

Is it possible for you, to show us what is inside your clipboard-file ?!
Seems it is either empty or contains no valid ascii-data.

You can ignore that warning. The button uses @runmode hide so you shouldn't see it.

The warning is because the first line clears the clipboard and the second line is then run once per file to append each file to the clipboard. The first file will be appended to the empty clipboard and thus produce that warning.

If you're only ever going to use the button with one file then you could simplify it to just run SetClip -f {filepath$}

[quote]...and when i try to paste text in editor i get this:

"
˙ţA"[/quote]
I don't think SetClip understands Unicode text files so that might be the problem.

[quote="tbone"]Is it possible for you, to show us what is inside your clipboard-file ?!
Seems it is either empty or contains no valid ascii-data.[/quote]

This is: (in hex)
0D 0A FF FE 41

OK, now i know what is bad:
1.When i tried to put into clipboard file in DOS codepage, it will work
2.File "Fajne_teksty.txt" is encoded as "U-DOS" - unicode...

Leo, is possible to add in SetClip unicode detection ?

Anybody know how to import a unicode text file to clipboard?

Check this commandline tool called NirCmd

NirCmd looks like it does the same as SetClip, i.e. the input file has to be a "simple text file" and there's no way to specify the codepage and translate it into UTF-16 before setting the clipboard.

I'd like to add options to SetClip so that you can specify the codepage of the input file, and also make it auto-detect UTF-8 and UTF-16 when there is a BOM at the start of the file, but it might take me a while to find the time.

Here is a bit of an update to this if people are still interested in that 14 years later :stuck_out_tongue: ...

A big powershell one liner:

powershell -executionpolicy bypass -command "Set-Clipboard -Value $Null; $Clip = '{allfilepath$|sep=~}'; $Clip = $Clip.Split('~'); ForEach ($Line In $Clip) { $Text = GCI -LiteralPath $Line | GC -Raw; Set-Clipboard -Append $Text`n; } $ClipFinal = Get-Clipboard | Out-String; $ClipFinal = $ClipFinal.Trim(); Set-Clipboard $ClipFinal; exit"

There is also this registry trick but I prefer the first one because it does not work with all text documents, only certain extensions.

Maybe there is a shorter dopus only way to go about this? Feel free to let me know.

You could do using scripting these days, as that provides ways to convert between encodings and set the clipboard.

But if the powershell method works and isn’t too slow (usually the main issue with powershell stuff) then I would keep using that.

This script command looks quite useful:

Thanks for this folks I actually ended up mixing a bit of everything I compiled a similar script to exe and now I just:

C:\Users\$ENV:USERNAME\Documents\SEND-TO\ClipText.exe {allfilepath$}

This works faster just like setclip and the registry tweak rather than using just powershell directly like leo said.

Set-Clipboard -Value $Null;

ForEach ($Item in $Args) { 

    $Clip = GCI -LiteralPath $Item | GC -Raw;

    Set-Clipboard -Append $Clip`n;

}

$ClipFinal = Get-Clipboard | Out-String; 

$ClipFinal = $ClipFinal.Trim();

Set-Clipboard $ClipFinal;

exit
1 Like