Batch file detect if specific tab is open?

你。 提交于 2019-12-11 10:29:02

问题


I want to let my script check, if a specific tab is open or not in google chrome, for example "https://stackoverflow.com/".

I know how to check if the browser runs at all, but I am not sure, if it's possible to let check it if an specific tab is open.

Does someone has an idea, how i could realize this?


回答1:


Sort of..

First you need OpenList extension for chrome.Then you need snedkeys.bat. This is a script in the same directory as the snedKeys.bat.It will list all opened links in chrome:

@echo off

start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "chrome-extension://nkpjembldfckmdchbdiclhfedcngbgnl/popup.html?focusHack"

::sleeps for 5 seconds
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:5  >nul 2>&1

::call sendKeys.bat ""  "^A"

::w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:5  >nul 2>&1

call sendKeys.bat ""  "^c"

w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:5  >nul 2>&1

for /f "usebackq tokens=* delims=" %%i in (
   `mshta "javascript:Code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(clipboardData.getData('Text'))));"`
) do (
 echo cntent of the clipboard:
 echo "%%i"
)

You can filter the result with FINDSTR or FIND to check if desired link is open.

E.g. this will check if stackoverflow is open:

@echo off

start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "chrome-extension://nkpjembldfckmdchbdiclhfedcngbgnl/popup.html?focusHack"

::sleeps for 5 seconds
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:5  >nul 2>&1

call sendKeys.bat ""  "^c"

for /f "usebackq tokens=* delims=" %%i in (
   `mshta "javascript:Code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(clipboardData.getData('Text'))));"`
) do (
 echo "%%i"| find "stackoverflow" >nul 2>&1 && (
    echo stackoverflow is open
 )
)

call sendKeys.bat ""  "^w"



回答2:


Yes:

tasklist /V | find /i "chrome"

will show you the title of the open tab that has focus.



来源:https://stackoverflow.com/questions/34671901/batch-file-detect-if-specific-tab-is-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!