GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Help with Clipboard Copyname button

Hi and good day to everyone.
Here's the deal: I want to make a button that let me to do the following:
Copy selected files full path to clipboard (in a single line), but if there's no files selected, copy the sourcepath.
Hope some can help me.

Really? No one?

Probably nobody has any ideas... I don't think you can do what you want, even with some scripting glue. Opus doesn't really have conditional logic capabilities such as what you're asking to do would require.

I think you'd need to figure out which action you want to perform on your own, and handle it with something like a triple-button that lets you get filenames from left mouse click - and current path from right mouse click (for example).

Maybe this is close enough:

Clipboard SET {sourcepath$} {allfilepath}

This will always include the sourcepath. I presume whatever you're going to use this for is likely going to have to test to see if the single clipboard item is a folder or a file, and then do something, perhaps you can modify your usage to use the logic:

  • If there is a single item, no items were selected (the clipboard item is the sourcepath)
  • If there are more than one item, ignore the first, and the remaining items are your selected file filepaths.

[quote="MrC"]Maybe this is close enough:

Clipboard SET {sourcepath$} {allfilepath}
Thanks but this is not what I'm looking for. What i need is a button that copy full path of the selected files and/or folders. if there's nothing selected copy to clipboard the sourcepath.
Maybe with a DOS button using contidional if? But I can't make this work!!!
Any help?

What will you be doing next with the text on the clipboard?

I think I know a way... If you link your account I'll test it a bit more and write it up for you tonight or tomorrow. (It's quite late here at the mo.)

Hmmm... I worked out a way that seems to work in a variety of scenarios. It needs an external script - as I couldn't figure out how to do it as an MS-DOS Batch Function entirely within Opus without getting some strange results.

First, a button definition you can add to any toolbar:

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>Copy Path to Clipboard</label> <icon1>#clipcopy</icon1> <function type="normal"> <instruction>@runmode hide</instruction> <instruction>dopusrt /cmd clipboard copynames=single</instruction> <instruction>/scripts\clipset.cmd {alias|home} {s|noterm} {allfilepath}</instruction> </function> </button>
It calls "dopusrt" to run the regular Opus 'clipboard copynames=single' internal command to get any selected files and folders into the clipboard on a single line - as requested. If nothing is selected, then this command doesn't do anything to the clipboard - whatever was there stays there. I had to use "dopusrt" because otherwise - if NO files or folders are selected, then the button stays grayed out and can't be clicked.

Regardless of whether or not the first command does anything (again, depending on whether or not you have anything selected) the button then ALWAYS calls the batch file from the /scripts folder alias. That's an alias I've created on my system that points to /dopusdata\Scripts. You can put the batch file wherever you want, just then modify the path in the button... The batch file (named clipset.cmd) should contain the following code:

[code]@echo off

if (%3)==() goto set
goto end

set _exe=%1
call :dequote _exe
::echo %_exe%
set _dir=%2
call :dequote _dir
::echo %_dir%
"%_exe%dopusrt.exe" /cmd clipboard set %_dir%
goto end

for /f "delims=" %%a in ('echo %%%1%%') do set %1=%%~a
goto :eof

The button is calling the batch script with 3 arguments:

[ol][li]The path to the Opus /home folder alias... this is to allow the script to find the dopusrt.exe program it needs to call in order to set the current path to the clipboard. In case you install Opus to a custom folder, this will then always work without having to hard code the path to dopusrt.exe.[/li]
[li]The current path... without the trailing backslash (which you can change in the button if you want).[/li]
[li]Any/all selected file/folder names...[/li][/ol]
...if the script sees that there is SOMETHING passed in the third argument, which happens if you run the button with any items selected, then the script just exits - assuming that you got what you wanted into the clipboard from the 'dopusrt /cmd clipboard copynames' command in the button before the script ever got called. If the script sees that there is NOTHING passed in the third argument, then it does some subroutine stuff to strip off the double-quotes chars passed in the first two args, then uses those fixed up paths to run dopusrt.exe to set the clipboard to the current path.

I got a bunch of strange results when I tried something like this before my first reply... but after seeing Leo's message - tried again and came up with something that I think will work. go link your account like Leo requested :slight_smile:.

I was using a much more simple command which just ran SetClip.exe -e, then SetClip.exe -a {sourcepath$}{file}

It seemed to work but I have not tested it fully. Been working on a new video most of the day, but I'll take some time out to look at this some more if the OP's account is linked.

[quote="leo"]I was using a much more simple command which just ran SetClip.exe -e, then SetClip.exe -a {sourcepath$}{file}

It seemed to work but I have not tested it fully. Been working on a new video most of the day, but I'll take some time out to look at this some more if the OP's account is linked.[/quote]
Ah, I had monkeyed around with something similar myself, but saw there was a strange issue with combining {s} and {o!} with spaces in the path string - in the case you don't have anything selected.


  • Clicking the button when located in a path: C:\ProgramData\GPSoftware\Directory Opus
  • Results in the following clipboard content: C:\ProgramData\GPSoftware\Directory Opus"

...i.e. there's a trailing double-quote. It's partially what had me screwing around with the 'dequote' subroutine in the batch method I posted, and attempts in either case to get around it with @nofilenamequoting don't work out quite right in some cases.

Ah, the MS-DOS quote-escaping rules strike again.

Thanks guys and especially steje. With your button now I figured out how to make it work.
Anyway, I make something similar using nircmd, it works except in Collections or Libraries.

nircmd clipboard clear
Clipboard ADD SET "{sourcepath|noterm}\{file}" 

When I come home I link my account

I had to add the path to nircmd.

If you've got a way that works, great!

Some feedback: The "|noterm" switch strips the trailing backslash character out of the {sourcepath} string... but then you're just adding it back again in your button before adding {file}. You could just shorten the control code to "{sourcepath}{file}" to get the same result.

Also, noticed that the Opus internal ADD switch is working for the SET sub-command to the clipboard function. Nice, since I didn't think it was documented as working for the set command (as opposed to copy / cut) but great that it does work. I also noticed though, that a side effect of using it is that you've got double-quoted strings back to back ("file1""file2"). If it "works" for you - great. Otherwise, the more complicated version I came up with corrects those shortcomings, and also adds the current folder path without any double-quotes at all - or the trailing backslash.