Created
May 21, 2018 01:34
-
-
Save pt2121/107bc3ca25f896e986e29fdd3c3780ce to your computer and use it in GitHub Desktop.
get a screenshot from an Android device and resize it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env stack | |
| -- stack --resolver lts-10.2 script | |
| {-# LANGUAGE OverloadedStrings #-} | |
| import Turtle | |
| import Control.Monad.IO.Class (MonadIO(..)) | |
| import Data.Maybe | |
| main = do | |
| let fileName = path "screen.png" | |
| let outPath = path "." | |
| let tmp = path "/sdcard" </> fileName | |
| let output = outPath </> fileName | |
| stdout $ | |
| screencap tmp | |
| <|> (adbPull tmp $ Just outPath) | |
| <|> resize output | |
| <|> adbShellRm tmp | |
| path p = p :: Turtle.FilePath | |
| adb :: [Text] -> Shell Text | |
| adb args = inproc "adb" args empty | |
| adbShell :: [Text] -> Shell Text | |
| adbShell args = adb $ "shell" : args | |
| adbPull :: Turtle.FilePath -> Maybe Turtle.FilePath -> Shell Text | |
| adbPull source destination = adb $ "pull" : ((format fp) <$> source : maybeToList destination) | |
| adbShellRm :: Turtle.FilePath -> Shell Text | |
| adbShellRm path = adbShell [ "rm", format fp path ] | |
| screencap :: Turtle.FilePath -> Shell Text | |
| screencap path = adbShell [ "screencap", "-p", format fp path ] | |
| resize :: Turtle.FilePath -> Shell Text | |
| resize path = inproc "mogrify" [ "-resize", "30%", format fp path ] empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment