Discussion:
Working batch script to append to the browser-independent global bookmarks file
(too old to reply)
Marion
2025-01-23 23:14:48 UTC
Permalink
So that everyone benefits from every post, here is a working script that
appends to the global system-wide bookmark file any link you'd like to add.

@echo off
REM addbm.bat adds another link to the global bookmark file
setlocal
setlocal EnableDelayedExpansion

REM #1 Set your favorite text or HTML editor
REM set editor=notepad++
set editor=gvim

REM #2 Set the location of your global bookmark HTML file
set bmfile=C:\path\to\global\bookmarks\file\bm.htm
echo.Global bookmark file is %bmfile%

:input_html
echo.Enter URL: ; e.g., https://amazon.com/vine/about
set /p "url="
echo.Enter Description: ; e.g., Amazon Vine Program
set /p "description="

echo.Adding... "%url%" as "%description%"

:append_html
echo.^<A HREF="%url%"^>%description%^</A^>^<P^> >> %bmfile%
echo."%url%" as "%description%" added to "%bmfile%"

:edit_html
echo Do you want to edit the global bookmark file? [y/n]
set /p "choice="
if /i "%choice%"=="y" (
echo Editing file: %bmfile%
%editor% %bmfile%
) else if /i "%choice%"=="n" (
echo File editing canceled.
)

pause
endlocal

As always, please improve so that billions of people can use this script.
As a Usenet goal is to learn from others & further improve their results.

Note that a longer more detailed thread on this topic can be found here:
*How to edit HTML source file on Windows in one step (not two)?*
<https://www.novabbs.com/computers/article-flat.php?id=84218&group=alt.comp.os.windows-10#84218>
Marion
2025-01-24 01:13:01 UTC
Permalink
Here's another (more sophisticated) variant of the appending to a simple
global bookmarks text HTML file, one per system, for all web browsers.

This batch file started with the prior batch file which simply added a
defined bookmark given the exact URL and description... and flipped the
algorithm around to simply ask for the desired search terms.

Assuming, for example, the desired search terms of "gas camp stove",
this batch script below appends to a global search HTML text file.

While this approach can be applied to any search engine, my specific need
was for the specific syntax of the Amazon and Amazon Vine search engines.
<https://amazon.com> and <https://amazon.com/vine/about>

Note that the syntax for a purely Amazon search is the following:
<A HREF=https://amazon.com/s?k=gas+camp+stove>[amazon] gas camp stove</A><P>

Note that the syntax for any specific Amazon Vine search is the following:
<A HREF=https://amazon.com/vine/vine-items?search=gas%20camp%20stove>[vine] gas camp stove</A><P>

It was a pain getting the angle brackets escaped in the Windows batch
file but that was nothing in effort compared to the way Amazon does things
where there are plus signs ("+") and %20 characters in real search terms.

Specifically, it was most miserable getting the Vine %20 to be escaped.

Having figured it out today, the advantage of me kind-heartedly generously
posting my results for you to benefit from is that you can munge what I
provide below to fit any search engine terms that you need to add for
your own global bookmarks search file (which everyone should have).

That makes all my effort writing this leveraged to everyone out there.
As always, please test & improve so that everyone benefits from every post.

@echo off
REM addvine.bat adds amazon & vine search links to a global Vine html file
setlocal
setlocal EnableDelayedExpansion

REM #1 set your favorite text HTML editor
REM set editor=notepad++
set editor=gvim

REM #2 set the location of your global vine search file
set vinefile=C:\path\to\your\global\search\file\vine.htm
echo.Global vine HTML search file is %vinefile%

:input_item
echo.Enter search item: ; for example, gas camp stove
set /p "item="

:replace_spaces_with_+
set "amazon_item=%item: =+%"

:replace_spaces_with_%20
set "vine_item="
for %%a in (%item%) do (
if "%%a"=="" (
set "vine_item=!vine_item!%%20"
) else (
if defined vine_item (
set "vine_item=!vine_item!%%20"
)
set "vine_item=!vine_item!%%a"
)
)

echo Original item: %item%
echo Amazon item: %amazon_item%
set vine_item=!vine_item!
echo Vine item: %vine_item%
echo.Adding... "%amazon_item%" and "!vine_item!" to %vinefile%

:append_html
echo.^<A HREF=https://amazon.com/s?k=%amazon_item%^>[amazon] %item%^</A^>^<P^> >> %vinefile%
echo.^<A HREF=https://amazon.com/vine/vine-items?search=%vine_item%^>[vine] %item%^</A^>^<P^> >> %vinefile%

:edit_html
echo Do you want to edit the global vine HTML file? [y/n]
set /p "choice="
if /i "%choice%"=="y" (
echo Editing file: %vinefile%
%editor% %vinefile%
) else if /i "%choice%"=="n" (
echo File editing canceled.
)

pause
endlocal
--
R.Wieser
2025-01-24 07:32:06 UTC
Permalink
Arlen,
echo.Enter URL: set /p "url="
echo.Enter Description: ; e.g., Amazon Vine Program
set /p "description="
:append_html
echo.^<A HREF="%url%"^>%description%^</A^>^<P^> >> %bmfile%
That will work as long as you're not using one of HTML's special chars,
like, from the top of my head, "&", "<" and">". Especially the "<" will
cause problems

IOW, you need to sanitize the users input.
:replace_spaces_with_+
set "amazon_item=%item: =+%"
And by the way: did you know that you can have "set /p" display a bit of
text before displaying the input prompt ? Like this :

set /p "url=Url: "

Regards,
Rudy Wieser

Loading...