Search code examples
batch-filedetectiondetect

Batch file detect if specific tab is open?


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?


Solution

  • 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"