Take screenshot with a unique file name #15

Closed
opened 2024-09-04 20:22:16 +02:00 by Benjamin_Loison · 1 comment
counter=0
get_file_name() {
    echo screenshot_$1.png
}
while [ -f `get_file_name $counter` ]
do
    ((counter++))
done
fileName=`get_file_name $counter`
adb exec-out screencap -p > $fileName
if [ ! -s $fileName ]
then
    echo "Screenshot couldn't be taken!"
    # To avoid having an empty file.
    rm $fileName
fi

Source: the Stack Overflow question 9964823

```bash counter=0 get_file_name() { echo screenshot_$1.png } while [ -f `get_file_name $counter` ] do ((counter++)) done fileName=`get_file_name $counter` adb exec-out screencap -p > $fileName if [ ! -s $fileName ] then echo "Screenshot couldn't be taken!" # To avoid having an empty file. rm $fileName fi ``` Source: [the Stack Overflow question 9964823](https://stackoverflow.com/q/9964823)
Author
Owner
adb exec-out screencap -h
usage: screencap [-hp] [-d display-id] [FILENAME]
   -h: this message
   -p: save the file as a png.
   -d: specify the display ID to capture (default: 4630947175487691137)
       see "dumpsys SurfaceFlinger --display-id" for valid display IDs.
   --hint-for-seamless If set will use the hintForSeamless path in SF

If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

so no forcing parameter.

Related to Benjamin-Loison/android/issues/70.

```bash adb exec-out screencap -h ``` ``` usage: screencap [-hp] [-d display-id] [FILENAME] -h: this message -p: save the file as a png. -d: specify the display ID to capture (default: 4630947175487691137) see "dumpsys SurfaceFlinger --display-id" for valid display IDs. --hint-for-seamless If set will use the hintForSeamless path in SF If FILENAME ends with .png it will be saved as a png. If FILENAME is not given, the results will be printed to stdout. ``` so no forcing parameter. Related to [Benjamin-Loison/android/issues/70](https://github.com/Benjamin-Loison/android/issues/70).
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Benjamin_Loison/adb#15
No description provided.