Dump W95 clipboard contents to file using batch file?

164 views
Skip to first unread message

Roger Hunt

unread,
Dec 1, 2002, 11:38:05 AM12/1/02
to
Greetings

(W95b)
I download lots of assorted stuff and have got into the habit of keeping
an "origin.txt" file, containing the download URL, with each download.

Generally I download to desktop then generate the origin.txt and open it
with Notepad.exe, using a batch file, and then save both to disc
elsewhere.
My routine now is to paste the URL to origin.txt then save and exit.
What I would like to do is write a batch file that will dump the
contents of Windows clipboard (the download URL) directly to this file.
(saving an onerous three mouse clicks each time).

Would it be feasible or possible to do this using a batch file?
I'm not sure where to start with the Clipboard bit - I'd be v. grateful
for any advice or pointers.

Cheers
--
Roger Hunt

William Allen

unread,
Dec 1, 2002, 12:12:40 PM12/1/02
to
"Roger Hunt" wrote in message

This is fairly easy by making the Batch File use the CSCRIPT interface
to WSH (See Note 1). It needs no third-party utilities.

This demo shows how to have a Batch file invoke Notepad for you and
automatically paste the current clipboard contents into a file you specify.

Specify the file as the first parameter to the Batch file, thus:

demo.bat MyFile.TXT

(the default is CLIP.TXT)

====Begin cut-and-paste (omit this line)
@ECHO OFF
SET FN=%1
IF ()==(%1) SET FN=CLIP.TXT

:: Open a blank new file
REM New file>%FN%

ECHO.set sh=WScript.CreateObject("WScript.Shell")>_TEMP.VBS
ECHO.sh.Run("Notepad.exe %FN%")>>_TEMP.VBS
ECHO.WScript.Sleep(200)>>_TEMP.VBS
ECHO.sh.SendKeys("^+{end}^{v}%%{F4}{enter}{enter}")>>_TEMP.VBS
cscript//nologo _TEMP.VBS

ECHO. The clipboard contents are:
TYPE %FN%

:: Clean up
DEL _TEMP.VBS
SET FN=

====End cut-and-paste (omit this line)
Win9x GUI study/demo only. Cut-and-paste as Batch script (file with .BAT
extension). Lines that don't begin with 2 spaces have wrapped by mistake.
Requires WSH (see Note 1)

If you want the Batch file always to append to an existing file,
simply remove the two lines:

:: Open a blank new file
REM New file>%FN%

--
William Allen

WSH (Windows Script Host) enables routine tasks to be handled in either
VBScript or JScript. It's available as a free downloadable add-on for
the tiny proportion of Windows machines (mostly older Windows 95 ones)
which don't already have it (in one version or another). Documentation
is included as an HTML help file, and includes cut-and-pastable syntax
examples in VBScript and JScript for all features. Current version is
5.6ish and installs on Win95 machines (although the notes mention only
Win98 upwards).

Windows Script Host information/upgrade-to-current-version/downloads:
http://msdn.microsoft.com/scripting/

By default, WSH installs CSCRIPT.EXE which is a Batch file
interface allowing all WSH functionality to be run from a normal
DOS-style Batch file. This interface provides Windows machines
with a massive extension to the traditional Batch functionality.


Roger Hunt

unread,
Dec 1, 2002, 1:03:39 PM12/1/02
to
In article <asdfur$q6dbi$1...@ID-55970.news.dfncis.de>, William Allen
<news...@mayfly13.fsnet.co.uk> wrote

>"Roger Hunt" wrote in message
>> Greetings
>>
>> (W95b)
>> I download lots of assorted stuff and have got into the habit of keeping
>> an "origin.txt" file, containing the download URL, with each download.
>>
>> Generally I download to desktop then generate the origin.txt and open it
>> with Notepad.exe, using a batch file, and then save both to disc
>> elsewhere.
>> My routine now is to paste the URL to origin.txt then save and exit.
>> What I would like to do is write a batch file that will dump the
>> contents of Windows clipboard (the download URL) directly to this file.
>> (saving an onerous three mouse clicks each time).
>>
>> Would it be feasible or possible to do this using a batch file?
>> I'm not sure where to start with the Clipboard bit - I'd be v. grateful
>> for any advice or pointers.
>
>This is fairly easy by making the Batch File use the CSCRIPT interface
>to WSH (See Note 1). It needs no third-party utilities.
>
(snip, paste, save, very helpful reply. Soon using WSH to do this)

Thanks very much for that!
WSH is a new door for me and it looks very useful indeed.
I shall go read up and have a play.

Cheers
--
Roger Hunt

William Allen

unread,
Dec 1, 2002, 4:05:04 PM12/1/02
to
"Roger Hunt" wrote in message
> In article William Allen wrote

> >"Roger Hunt" wrote in message
...snip

> >> What I would like to do is write a batch file that will dump the
> >> contents of Windows clipboard
..snip

> >This is fairly easy by making the Batch File use the CSCRIPT interface
> >to WSH (See Note 1). It needs no third-party utilities.
> >
> (snip, paste, save, very helpful reply. Soon using WSH to do this)
>
> Thanks very much for that!
> WSH is a new door for me and it looks very useful indeed.
> I shall go read up and have a play.

Once you have the WSH help documentation (file is SCRIPT56.CHM
for version 5.6) the key method to search for is: SendKeys

In the documentation file under the SendKeys method is a complete
table to explain all the codes, such as those used in the line:


SendKeys("^+{end}^{v}%%{F4}{enter}{enter}")

Note, however, that because the % character is special in Batch
files, you need to double it, thus %%{F4} to get a literal %{F4}
sent. % is the code for an Alt-combo, so %{F4} is Alt-F4 which
closes the Notepad instance opened to grab the clipboard.

--
William Allen


Roger Hunt

unread,
Dec 1, 2002, 5:09:35 PM12/1/02
to
In article <asdtk4$q25lj$1...@ID-55970.news.dfncis.de>, William Allen
<news...@mayfly13.fsnet.co.uk> wrote

>"Roger Hunt" wrote in message
>> In article William Allen wrote
>> >"Roger Hunt" wrote in message
>...snip
>> >> What I would like to do is write a batch file that will dump the
>> >> contents of Windows clipboard
>..snip
>> >This is fairly easy by making the Batch File use the CSCRIPT interface
>> >to WSH (See Note 1). It needs no third-party utilities.
>> >
>> (snip, paste, save, very helpful reply. Soon using WSH to do this)
>>
>> Thanks very much for that!
>> WSH is a new door for me and it looks very useful indeed.
>> I shall go read up and have a play.
>
>Once you have the WSH help documentation (file is SCRIPT56.CHM
>for version 5.6) the key method to search for is: SendKeys
>
My W95b came with WSH 5.1 and it could be that the documentation is
somewhere on disc, or in the Resource Kit maybe, but much better to
download 5.6 with it's own huge documentation.

>In the documentation file under the SendKeys method is a complete
>table to explain all the codes, such as those used in the line:
> SendKeys("^+{end}^{v}%%{F4}{enter}{enter}")
>
Yikes! I'll be referring to that table quite a lot I think.

>Note, however, that because the % character is special in Batch
>files, you need to double it, thus %%{F4} to get a literal %{F4}
>sent. % is the code for an Alt-combo, so %{F4} is Alt-F4 which
>closes the Notepad instance opened to grab the clipboard.
>
Noted.

Regards
--
Roger Hunt

Reply all
Reply to author
Forward
0 new messages