Search code examples
androidshellbatch-fileadb

How to use Windows batch file to create a Txt file on a sony device SD card


I am trying to automate a txt file to be created and installed to an android phone.

Hi, I have created a batch file to automate a script, setting up a Sony device. The script works fine and is great, however I am now trying to create a Txt file that stores information of the version and date that the device was scripted within the internal memory.

So far, all I need to do is set the device to developer mode, enable USB debugging then double click the windows batch file and it runs as expected. the list of commands follow as such:

\
shell input tap 0358 1108 #all apps\
shell input tap 0610 0802 #settings\
shell input tap 0343 0427 #wifi\
shell input tap 0674 0101 #3 dots\
shell input tap 0437 0290 #advanced\
shell input tap 0630 0252 #network notification off \
shell input keyevent 4 #back\
shell input keyevent 4 #exit\
shell input tap 0350 0552 #bluetooth\
shell input tap 0635 0212 #on\
shell input keyevent 4 #exit\
shell input tap 0357 0871 #more\
shell input tap 0340 0410 #android beam\
shell input tap 0648 0198 #off .........

This continues further and again works great. What I am trying to achieve is that the script creates a Txt files within the SD card, so I can refer back to which version the script used in the many months to come. So far I can achieve the following by manually opening CMD.

adb shell \
shell@F3311:/ $ echo "#Sony_Script \t#Version 1.0 \n\n \t\t#08/11/2022" > /sdcard/Android/data/ScriptVersion.txt

This creates the file as expected within the directory. However I haven't got the time to do this manually for every device and would like this automated but it never seems to work.

I don't want to open adb shell every time to do this, I am hoping to implement it within the original batch file so it can run in the background. I hope this makes sense. Below is the windows batch file I have created.

setlocal ENABLEDELAYEDEXPANSION\
@echo off

REM adb command to grab all connected devices

adb devices > adb.txt
findstr /v "List of devices attached" adb.txt > clean.txt

for /f "tokens=*" %%a in (Version.txt) do (
    for /f "tokens=1" %%b in (clean.txt) do (
        echo adb -s %%b %%a
        start adb -s %%b %%a
    )

    TIMEOUT /T 4
)

Solution

  • Maintain a script with version, something like

    :
    #Sony_Script    
    #Version 1.0
    #08/11/2022
    input tap 0358 1108 #all apps
    input tap 0610 0802 #settings
    input tap 0343 0427 #wifi
    input tap 0674 0101 #3 dots
    input tap 0437 0290 #advanced
    input tap 0630 0252 #network notification off
    ...
    

    then

    adb push myscript /sdcard/
    adb shell sh /sdcard/myscript
    

    you will know exactly what was executed on each device