.batch ファイル経由で現在のタブの URL を取得する

.batch ファイル経由で現在のタブの URL を取得する

.batch私は Firefox を使用していますが、ファイル経由でアクティブなタブの URL を取得する方法はありますか?

たとえば、Firefox のアクティブ タブの URL が の場合、ファイルを使用してwhatever.com取得する必要があります。whatever.combat

答え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%"

関連情報