[FIXED] adb shell check if screen is on windows cmd

Issue

I want to create bat script to turn on screen.
This command adb shell dumpsys input_method | find "mWakefulness=" is back me result

mWakefulness=Asleep
mWakefulness=Awake

I want to check if adb back Asleep result if not i will turn it on, for example

cd /d "C:\Program Files (x86)\Remote\adb"
SET CHECK="adb shell dumpsys input_method | find "mWakefulness=""
if %CHECK% == "mWakefulness=Asleep" (
    adb shell input keyevent 26
) 

But looks I’m on wrong way and can’t find how to do this, I’m not good in windows and their cmd.

Solution

Found solution

@echo off
cd /d "C:\Program Files (x86)\Remote\adb"


setlocal
for /f "delims= tokens=1*" %%a in ('adb shell dumpsys power ^| findstr.exe "mWakefulness=Asleep"') DO (
for /f "delims== tokens=2*" %%S in ("%%a") do (
if "%%S" == "false" (goto move1) else (goto move2)
)
)

:move1
goto end

:move2
start /MIN cmd /c adb shell input keyevent 26
goto end

:end
exit

Answered By – user994461

Answer Checked By – Terry (FixeMe Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *