通过 .batch 文件获取当前标签的 URL

通过 .batch 文件获取当前标签的 URL

我是 Firefox 用户,有什么方法可以通过.batch文件获取活动选项卡的 URL?

例如,如果 Firefox 中活动选项卡的 url 是whatever.com,则我需要whatever.com使用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%"

相关内容