(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
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.
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
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
Regards
--
Roger Hunt