ADB GUI

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
adegard
Posts: 90
Joined: 24 Nov 2017, 05:58
Contact:

ADB GUI

Post by adegard » 01 May 2020, 09:31

I found this tool very useful to transfert files from pc to android, thanks to @linpinger :clap: So I decide to do some translations.

In order to use it you need ADB bridge for Android. Anyway I suggest you to use scrcpy package, which contains also adb.exe and have a android mirror app

Installation: - ADB installation
- Open the USB debugging in the developer options, connect your phone with USB and then run scrcpy
- Open then program ADB GUI (ahk below)
- The interface allows drag and drop of files to the listview, also Folder creation easily

Image

ADB GUI ahk, EN:

Code: Select all

;https://www.autohotkey.com/boards/viewtopic.php?t=3480

#SingleInstance, off
verDate := "2014-5-4"

bDebug := 1  ; // Whether to use the version

if bDebug
{
	developADB := "D:\bin\Java\Android\sdk\platform-tools\adb.exe"
	LocList := "C:\etc\|S:\|E:\|B:\etc\|D:\tmp\"
} else {
	developADB := "adb.exe"
	FileInstall, D:\bin\Java\Android\adb_cn\adb.exe, %A_scriptdir%\adb.exe, 0
	LocList := "D:\|E:\"
}

	; Set the PATH environment variable to avoid tossing behind
	EnvGet, Paths, PATH
	EnvSet, PATH, D:\bin\Java\Android\adb_cn`;D:\bin\Java\Android\sdk\platform-tools`;C:\bin\bin32`;D:\bin\bin32`;%A_scriptdir%\bin32`;%A_scriptdir%`;%Paths%

bOutUTF8 := false
;bOutUTF8 := true

	Gui,Add,Groupbox,x14 y10 w730 h390 cBlue vTip, Remote local directory and remote list:
	Gui,Add,checkbox,x640 y8 w730 h20 cBlue vbClickDown checked, Doubleclick download(&C)
	Gui,Add,Button,x654 y30 w80 h20 gNewShell vNewShell, Shell

	Gui,Add,Button,x454 y30 w80 h20 vShowDir gShowDir, display(&S)
	Gui,Add,ComboBox,x24 y30 w430 choose1 vDevDir, /sdcard/|/mnt/shell/emulated/0/|/Removable/MicroSD/

	Gui,Add,ComboBox,x544 y30 w100 vLocDir Choose1, %LocList%

	Gui, Font, S12
	Gui,Add,ListView,x24 y60 w710 h330 -ReadOnly AltSubmit gLVClick vFoxLV, Name|Size|Time
	Gui, Font
	LV_ModifyCol(1, 460) , LV_ModifyCol(2, 80) , LV_ModifyCol(3, 145)
		LV_Add("", "..", "D", "")

	Gui,Show,w751 h410 , ADB push pull by Irish Fox http://linpinger.github.io  Ver: %verDate%

	process, Exist, adb.exe
	if ( ErrorLevel = 0 ) {
		guicontrol, Disable, ShowDir
		runwait, %developADB% shell ls /, , Min
		guicontrol, Enable, ShowDir
	}
	gosub, menuinit
	Guicontrol, focus, ShowDir
	gosub, ShowDir
return

menuinit: ; Initialize the menu
	Menu, LVMenu, Add, Download to local(&F), FoxMenuAct
	Menu, LVMenu, Add
	Menu, LVMenu, Add, Move(&M), FoxMenuAct
	Menu, LVMenu, Add, new folder(&N), FoxMenuAct
	Menu, LVMenu, Add
	Menu, LVMenu, Add, delete(&D), FoxMenuAct
return

FoxMenuAct: ; Corresponding menu
	guicontrolget, DevDir
	LV_GetText(nowName, MenuRowNum, 1)
	If ( A_ThisMenuItem = "Move(&M)" ) {
		oldPath := DevDir . nowName
		inputbox, newPath, Move / Rename, enter the target path to be moved,,300, 150, , , , , %oldPath%
		if ( (oldPath = newPath) or newPath = "")
				return
		runwait, adb shell mv "%oldPath%" "%newPath%"
	}
	If ( A_ThisMenuItem = "new folder(&N)" ) {
		inputbox, newDirName, New folder, enter the name of the folder to be created,,300, 150
		if ( newDirName = "" )
			return
		runwait, adb shell mkdir %DevDir%%newDirName%
	}
	If ( A_ThisMenuItem = "Download to local(&F)" ) {
		guicontrolget, DevDir
		guicontrolget, LocDir
		NowRow := 1
		DownNameList := ""
		loop {
			NowRow := LV_GetNext(NowRow)
			if ! NowRow
					break
			LV_GetText(nowName, NowRow, 1)
			LV_GetText(nowSize, NowRow, 2)
			if ( nowSize = "D" )
				continue
			DownNameList .= nowName . "`n"
		} ; Get a list of names
		loop, parse, DownNameList, `n, `r
		{
				if ( A_LoopField = "" )
						continue
				nowName := A_LoopField
				if ( bOutUTF8 )
					runwait, adb pull "%DevDir%%nowName%" %nowName%, %LocDir%
				else
					runwait, adb pull "%DevDir%%nowName%" ., %LocDir%
		}
	}
	If ( A_ThisMenuItem = "delete(&D)" ) {
		if ( MenuRowNum < 2 )
			return
		LV_GetText(nowSize, MenuRowNum, 2)
		if ( nowSize = "D" ) {
			msgbox, 257, Confirm, confirm to delete the directory
			ifmsgbox, OK
				runwait, adb shell rm -r "%DevDir%%nowName%"
			else
				return
		}
		runwait, adb shell rm "%DevDir%%nowName%"
	}
	lsDir(DevDir, bOutUTF8)
return


NewShell:
	run, adb shell
return

LVClick: ; Double-click the entry
	nItem := A_EventInfo
	if ( A_GuiEvent == "E" ) { ; F2before
		LV_GetText(nEditBefore, nItem, 1)
	}
	if ( A_GuiEvent == "e" ) { ; F2Rear
		LV_GetText(nEditAfter, nItem, 1)
		if ( (nEditBefore = nEditAfter) or nEditAfter = "")
				return
		guicontrolget, DevDir
		runwait, adb shell mv "%DevDir%%nEditBefore%" "%DevDir%%nEditAfter%"
	}
	if ( A_GuiEvent = "DoubleClick" ) {
		LV_GetText(nowName, nItem, 1)
		LV_GetText(nowSize, nItem, 2)
		guicontrolget, DevDir
		if ( nowSize = "D" ) { ; table of Contents
			if ( nowName = ".." ) { ; Parent directory
				xx_1 := ""
				regexmatch(DevDir, "i)^([/]?.*/).+/$", xx_)
				if ( xx_1 != "" ) {
					guicontrol, Text, DevDir, %xx_1%
					lsDir(xx_1, bOutUTF8)
				}
			} else { ; Subordinate directory
				subDir := DevDir . nowName . "/"
				guicontrol, Text, DevDir, %subDir%
				lsDir(subDir, bOutUTF8)
			}
		} else if ( nowSize = "L" ) { ; link
			xx_1 := "" , xx_2 := ""
			; etc -> /system/etc
			regexmatch(nowName, "i)^(.*) -> (.*)", xx_)
			if ( xx_1 != "" ) {
				subDir := DevDir . xx_1 . "/"
				guicontrol, Text, DevDir, %subDir%
				lsDir(subDir, bOutUTF8)
			}
		} else { ; Ordinary file
			GuiControlGet, bClickDown
			if ( 1 = bClickDown ) { ; Double-click download
				if ( nItem < 2 )
					return
				if ( nowSize = "D" )
					return
				guicontrolget, LocDir
				if ( bOutUTF8 )
					runwait, adb pull "%DevDir%%nowName%" %nowName%, %LocDir%
				else
					runwait, adb pull "%DevDir%%nowName%" ., %LocDir%
			} else {
				remoteFilePath := DevDir . nowName
				guicontrol, , Tip, Remote local directory and remote list: %remoteFilePath%
				clipboard = %remoteFilePath%
			}
		}
	}
return

ShowDir: ; Show directory contents
	guicontrolget, DevDir
	lsDir(DevDir, bOutUTF8)
return


GuiContextMenu:     ; Menu: Show right-click menu
	If ( A_guicontrol = "FoxLV") {
		MenuRowNum := A_EventInfo
		Menu, LVMenu, Show, %A_GuiX%, %A_GuiY%
	}
return

GuiDropFiles:  ; Drag event
	File_full_path := A_GuiEvent
	if ( A_guicontrol = "FoxLV" ) {
		GuiControlGet, DevDir
		loop, parse, File_full_path, `n, `r
		{
			if ( A_loopfield = "" )
					continue
			FileGetSize, pushSize, %A_LoopField%, K
			sTime := A_TickCount
			runwait, adb push "%A_LoopField%" "%DevDir%"
			eTime := ( A_TickCount - sTime ) / 1000
			TrayTip, Pushspeed:, % pushSize / eTime . " K/s"
			lsDir(DevDir, bOutUTF8)
		}
	} else {
		TrayTip, Tip: To drag the file into the list box
	}
return

GuiEscape:
GuiClose:
	ExitApp
return


^esc::reload
+esc::Edit
!esc::ExitApp


lsDir(DevDir="/sdcard/", bUTF8=false)
{
	tmpFilePath := "C:\DevDir.lst"
	runwait, cmd /c adb shell ls -l "%DevDir%" > %tmpFilePath%, , Min
	if ( bUTF8 ) {
		fileread, nr, *P65001 %tmpFilePath%  ; UTF-8
	} else {
		fileread, nr, %tmpFilePath%
	}
	filedelete, %tmpFilePath%
	LV_Delete()
	LV_Add("", "..", "D")
	loop, parse, nr, `n, `r  ; table of Contents
	{	 ; drwxrwxr-x root     sdcard_rw          2014-03-25 21:56 aa
		if ( A_LoopField = "" )
			continue
		xx_1 := "", xx_2 := ""
		regexmatch(A_loopfield, "Ui)^d[rwx\-]+[ ]+[a-z\_\-0-9]+[ ]+[a-z\_\-0-9]+[ ]+[0-9]*([0-9]{4}-[0-9]{2}-[0-9]{2} *[0-9]{2}:[0-9]{2}) +(.*)$", xx_)
		if ( xx_2 = "" )
			continue
		LV_Add("", xx_2, "D", xx_1)
	}
	loop, parse, nr, `n, `r  ; link
	{	 ; lrwxrwxrwx root     root              1970-01-01 08:00 emmc@android -> /dev/block/mmcblk0p5
		if ( A_LoopField = "" )
			continue
		xx_1 := "", xx_2 := ""
		regexmatch(A_loopfield, "Ui)^l[rwx\-]+[ ]+[a-z\_\-0-9]+[ ]+[a-z\_\-0-9]+[ ]+[0-9]*([0-9]{4}-[0-9]{2}-[0-9]{2} *[0-9]{2}:[0-9]{2}) +(.*)$", xx_)
		if ( xx_2 = "" )
			continue
		LV_Add("", xx_2, "L", xx_1)
	}

	loop, parse, nr, `n, `r  ; file
	{	 ; -rw-rw-r-- root     sdcard_rw  2130142 2014-03-27 21:49 novel.zip
		if ( A_LoopField = "" )
			continue
		xx_1 := "", xx_2 := "", xx_3 := ""
		regexmatch(A_loopfield, "Ui)^[^dl].[rwx\-]+[ ]+[a-z\_\-0-9]+[ ]+[a-z\_\-0-9]+[ ]+([0-9]*) +([0-9]{4}-[0-9]{2}-[0-9]{2} *[0-9]{2}:[0-9]{2}) +(.*)$", xx_)
		if ( xx_1 = "" )
			continue
		LV_Add("", xx_3, xx_1, xx_2)
	}
}

TODO
  • I think some improvements should be done to list the folder files...
  • other adb commands
Last edited by adegard on 03 May 2020, 10:31, edited 7 times in total.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ADB GUI

Post by hasantr » 02 May 2020, 18:58

@adegard This caught my attention. But it did not succeed when I put it into the directory where adb files are located and run it. Need Android Studio?
User avatar
adegard
Posts: 90
Joined: 24 Nov 2017, 05:58
Contact:

Re: ADB GUI

Post by adegard » 03 May 2020, 08:04

Hi @hasantr
You don't need Android Studio
Anyway you can install and test adb following the below procedure:

Enable USB Debugging on Your Phone
To use ADB with your Android device, you must enable a feature called USB debugging. Open your phone’s app drawer, tap the Settings icon, and select “About Phone”. Scroll all the way down and tap the “Build Number” item seven times. You should get a message saying you are now a developer.

Head back to the main Settings page, and you should see a new option near the bottom called “Developer Options”. Open that, and enable “USB Debugging”.

Later on, when you connect your phone to your computer (usb), you’ll see a popup entitled “Allow USB Debugging?” on your phone. Check the “Always allow from this computer” box and tap OK.

Test ADB
Open the folder that you installed adb file in and open cmd prompt. This is where the ADB program is stored. Hold Shift and right-click inside the folder. Choose “Open Command Window Here”.

To test whether ADB is working properly, connect your Android device to your computer using a USB cable and run the following command:

Code: Select all

adb devices
Image

You should see a device in the list. If your device is connected but nothing appears in the list, you’ll need to install the appropriate drivers.

If it's ok, you will be able to use scrcpy (screen copy) and the above script
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ADB GUI

Post by hasantr » 07 May 2020, 16:46

adegard wrote:
03 May 2020, 08:04
Hi @hasantr
You don't need Android Studio
Anyway you can install and test adb following the below procedure:

Enable USB Debugging on Your Phone
To use ADB with your Android device, you must enable a feature called USB debugging. Open your phone’s app drawer, tap the Settings icon, and select “About Phone”. Scroll all the way down and tap the “Build Number” item seven times. You should get a message saying you are now a developer.

Head back to the main Settings page, and you should see a new option near the bottom called “Developer Options”. Open that, and enable “USB Debugging”.

Later on, when you connect your phone to your computer (usb), you’ll see a popup entitled “Allow USB Debugging?” on your phone. Check the “Always allow from this computer” box and tap OK.

Test ADB
Open the folder that you installed adb file in and open cmd prompt. This is where the ADB program is stored. Hold Shift and right-click inside the folder. Choose “Open Command Window Here”.

To test whether ADB is working properly, connect your Android device to your computer using a USB cable and run the following command:

Code: Select all

adb devices
Image

You should see a device in the list. If your device is connected but nothing appears in the list, you’ll need to install the appropriate drivers.

If it's ok, you will be able to use scrcpy (screen copy) and the above script
I am using portable adb driver.
Would you let me add it to my app if I could?
I am trying to make this kind of application.
I would like to add the functions of your application to my application. :roll:
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ADB GUI

Post by hasantr » 07 May 2020, 16:48

https://developer.android.com/studio/releases/platform-tools
This worked.

But I can't manage to put files on the memory card.

Can you achieve this?
User avatar
adegard
Posts: 90
Joined: 24 Nov 2017, 05:58
Contact:

Re: ADB GUI

Post by adegard » 08 May 2020, 14:46

Hi @hasantr
I didn't tried but, you should choose sdcard, like

Code: Select all

adb push C:\Users\Jonathan\Desktop\video.mp4 /sdcard/
in shell simply write

Code: Select all

push C:\Users\Jonathan\Desktop\video.mp4 /sdcard/
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: ADB GUI

Post by hasantr » 10 May 2020, 10:30

adegard wrote:
08 May 2020, 14:46
Hi @hasantr
I didn't tried but, you should choose sdcard, like

Code: Select all

adb push C:\Users\Jonathan\Desktop\video.mp4 /sdcard/
in shell simply write

Code: Select all

push C:\Users\Jonathan\Desktop\video.mp4 /sdcard/
Sdcard takes custom naming, but I found out it is accessible. Adaptation between Adb and Ahk was very easy. I decided to write my own function. :)
mobit_solutions
Posts: 1
Joined: 07 Jul 2020, 07:09

Re: ADB GUI

Post by mobit_solutions » 07 Jul 2020, 07:16

This catches my eye. But when I put it in the directory where adb files are located, and run it, it did not succeed.
Post Reply

Return to “Scripts and Functions (v1)”