Copy file contents to clipboard

One stupid question.
How to copy file content inside clipboard (not using external program like setclip / nircmd etc.).

Is opus have now this feature?

CLIPBOARD SET p:\directory\filename.txt

This will copy only "p:\directory\filename.txt" inside clipboard...

If you're using Opus 11, you can do it without using external tools via a few lines of script.

If you link your account I can show you how.

Yes, DO11.

What mean "link your account"?

"For priority support, link your forum account"

"Your accounts have been linked, and you now qualify for priority technical support."

Is linked now?
I don't see any difference.

Thank you!

When editing the toolbar button or hotkey, set the Function drop-down to Script Function.

In Opus 12 or above, set the Language drop-down to VBScript.

(If using Opus 11 instead, add an extra line with @script VBScript to what's below.)

Paste this code into the large, main field in the button editor:

Option Explicit

Function OnClick(ByRef ClickData)
	Dim fso, tfile, txt
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set tfile = fso.OpenTextFile("p:\directory\filename.txt")
	txt = tfile.ReadAll
	DOpus.SetClip txt
End Function

That will read p:\directory\filename.txt into memory and put the text into the clipboard.

  1. File exists:

002: Button, as defined:


After lauch - nothing happen.
Also clipboard contents are NOT CHANGED.
Did i set something wrong?

"set the Function drop-down to Script Function"

It's still set to Standard Function (Opus or external) in your screenshot.

Now works.

Do You plan to add to DO switch to load file into Clipboard?

Not currently. We think scripting handles this well now, and is more flexible.

Is a little strange to copy/paste over entire buttons where i want to use it.

Browse for file and add "CLIPBOARD CONTENT=".........." - or something like this will be simpliest way....

You could turn the script into a Script Add-In which adds a command you can use like that in other buttons. (The command would have to have a different name, since there's already a Clipboard command, but apart from that it could work exactly as you want.)

Script Add-ins

Adding a new Internal Command

To get you started, here is the updated code that will copy content of any selected file to clipboard :slight_smile:

Option Explicit

Function OnClick(ByRef ClickData)
   Dim fso, tfile, txt
   If ClickData.func.sourcetab.selected_files.Count > 0 Then
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set tfile = fso.OpenTextFile(ClickData.func.sourcetab.selected_files(0))
      txt = tfile.ReadAll
      DOpus.SetClip txt
   End If
End Function

[Script code updated, as per the next post below. --Leo]

Oops, replace the

If Len(ClickData.func.sourcetab.selected_files) > 0 Then

with

If ClickData.func.sourcetab.selected_files.Count > 0 Then

otherwise the script would throw error when nothing is selected :blush:

[Script code in the previous post has been edited and updated to include this change. --Leo]

Ok guys, thanks for help.

Hello. Is there a way to paste contents of certain file (ex., C:\1.txt) as new .txt files in {s}?

How would that be different from making a copy of 1.txt?

i want to copy its contents. for ex., file 1.txt contains this lines:
Directory Opus 1
Directory Opus 2
Directory Opus 3
...
Directory Opus 1000

i want to create 1000 new .txt files, a copy of "FileType NEW=.txt FROMCLIPBOARD" command, but from file, not clipboard...

I have test this code but it's doesn't works for me. where is my mistake?


I have select a .txt file and press this button. then open MS Word and press Ctrl+v. But its doesn't paste the text from the selected files.