Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android screenshot and video grab helper script for PowerShell
<#
.SYNOPSIS
Records a video to a temp file on the device then downloads to local system and deletes temp file.
.PARAMETER DestFile
Destination path and file on local file system
.NOTES
Author : Frode Nilsen <nilzor@gmail.com>
.EXAMPLE
And-Record c:\temp\video.mp4
.LINK #>
function global:And-Record() {
Param(
[Parameter(Position=1,Mandatory=$TRUE)]
[String] $DestFile
)
$FileName = [System.IO.Path]::GetFileName($DestFile)
Write-Host "Recording video to $FileName. Ctrl+C when done"
if ($FileName -eq "") { Write-Error "'DestFile' must include a file name" }
else {
$TempDeviceFile = "/sdcard/temp-video.mp4"
Start-Process -Wait "adb" -ArgumentList "shell screenrecord $TempDeviceFile"
adb pull $TempDeviceFile $DestFile
adb shell rm $TempDeviceFile
}
}
<#
.SYNOPSIS
Grabs a screenshot and optionally resizes it to a scale of choice.
.DESCRIPTION
Resizing depends on Imagemagick being installed.
.PARAMETER DestFile
Destination path and file on local file system
.PARAMETER ResizePercent
Scale in percentage. If not provided will not rescale
.NOTES
Author : Frode Nilsen <nilzor@gmail.com>
.EXAMPLE
And-Screenshot c:\temp\screenshot.png
.LINK
http://www.imagemagick.org/script/binary-releases.php#windows
#>
function global:And-Screenshot() {
Param(
[Parameter(Position=1,Mandatory=$TRUE)]
[String] $DestFile,
[Parameter(Position=2, Mandatory=$FALSE)]
[int] $ResizePercent
)
if ($ResizePercent -eq "") { $ResizePercent = "33" }
$FileName = [System.IO.Path]::GetFileName($DestFile)
if ($FileName -eq "") { Write-Error "'DestFile' must include a file name" }
else {
$ResizePercentStr = "$ResizePercent%"
$OutStr = "Screngrabbing to $DestFile"
if ($ResizePercent -ne "100") {
$OutStr += " and resizing to $ResizePercentStr of original size"
}
Write-Host $OutStr
$TempDeviceFile = "/sdcard/temp-screen.png"
adb shell screencap -p $TempDeviceFile
adb pull $TempDeviceFile $DestFile
adb shell rm $TempDeviceFile
if ($ResizePercent -ne "100") {
convert $DestFile -resize $ResizePercentStr $DestFile
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.