5

So - I'm using an image capture tool (snagit). By default, the image itself is saved to the clipboard (after a capture). I would prefer that the image's path stored in the clipboard.

The application allows me to (instead) save the file, and pass the image as an argument to an external application. I'm passing it to the following .vbs file:

Dim Clipboard
Set args = WScript.Arguments
if args.length > 0 then
    arg1 = trim(args.Item(0))
else
    arg1 = "(No Data)"
end if

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /C echo "&arg1&" | CLIP", 2

This does 99% of what I want, except I find that 'ECHO ... | CLIP' tends to append formfeed/carriage return chars to my string.

Is there a better command I can use (in either cmd/vbs)?

Thanks in advance.

1 Answers1

6

I seriously doubt your code produces <formfeed><carriage return> on the clipboard. It should produce <carriage return><line feed> at the end. Those are the standard line termination characters on Windows. They are automatically added by the ECHO command.

You can write to stdout without the new line using <NUL SET /P "=message"

I don't understand why you are using VBS when it can't access the clipboard directly. It makes more sense to me to use a batch file.

@echo off
setlocal
set "arg1=%~1"
if not defined arg1 set "arg1=(No Data)"
<nul set /p "=%arg1%"|clip

or as a one line batch file:

@if "%~1"=="" (<nul set/p"=(No Data)"|clip) else <nul set/p"=%~1"|clip

If you really want to use VBS, then here it is

Dim args, arg1, objShell
Set args = WScript.Arguments
if args.length > 0 then
  arg1 = trim(args.Item(0))
else
  arg1 = "(No Data)"
end if

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /C <nul set /p ""="&arg1&""" | CLIP", 2
dbenham
  • 127,446
  • 28
  • 251
  • 390