Получить URL-адрес текущей вкладки через пакетный файл

Получить URL-адрес текущей вкладки через пакетный файл

Я пользователь Firefox. Есть ли способ получить URL активной вкладки через .batchфайл?

Например, если URL-адрес активной вкладки в Firefox — whatever.com, мне нужно получить файл whatever.comusing bat.

решение1

Только активная вкладка будет иметь заголовок, который можно обнаружить с помощью tasklist. Итак:

tasklist /v /fi "imagename eq firefox.exe"  |findstr /r /v "N/A"

или обработано с помощью FOR:

for /f "skip=1 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe"  ^|findstr /r /v "N/A"') do @echo %%b

хотя название может отличаться от ссылки.

Сsendkeys.batвы можете обмануть браузер, чтобы он изменил свой заголовок на текущую ссылку:

@echo off
::get the title of the active page
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe"  ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
::get the first 10 sympols needs to be passed to the sendkeys command
set "fftitle=%fftitle:~0,10%"
::opens the console of the browser
call sendkeys.bat "%fftitle%" "{f12}"
::waits for 2 seconds
w32tm /stripchart /computer:localhost /period:2 /dataonly /samples:2  1>nul
::changing the title with the link location
call sendkeys.bat "%fftitle%" "document.title=window.location.href{ENTER}"
::wait for 3 seconds
w32tm /stripchart /computer:localhost /period:3 /dataonly /samples:2  1>nul
::get the new title
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe"  ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
echo "%fftitle%"

Редактировать. Прямое открытие консоли:

@echo off
::get the title of the active page
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe"  ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
::get the first 10 sympols needs to be passed to the sendkeys command
set "fftitle=%fftitle:~0,10%"
::opens the console of the browser
call sendkeys.bat "%fftitle%" "^+K"
::waits for 2 seconds
w32tm /stripchart /computer:localhost /period:2 /dataonly /samples:2  1>nul
::changing the title with the link location
call sendkeys.bat "%fftitle%" "document.title=window.location.href{ENTER}"
::wait for 3 seconds
w32tm /stripchart /computer:localhost /period:3 /dataonly /samples:2  1>nul
::get the new title
for /f "skip=3 tokens=9* delims= " %%a in ('tasklist /v /fi "imagename eq firefox.exe"  ^|findstr /r /v "N/A nsAppShell:EventWindow"') do set "fftitle=%%b"
echo "%fftitle%"

Связанный контент