# Automation with Screenshot

**URL:** <https://discourse.asciinema.org/t/automation-with-screenshot/1054>\
**Category:** Show and tell\
**Created:** [December 11, 2025, 12:39pm UTC](https://discourse.asciinema.org/t/automation-with-screenshot/1054 "2025-12-11T12:39:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trdthg](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/trdthg/32/677_2.png) [@trdthg](https://discourse.asciinema.org/u/trdthg)\
**Post date:** [December 11, 2025, 12:39pm UTC](https://discourse.asciinema.org/t/automation-with-screenshot/1054/1 "2025-12-11T12:39:44Z")

</div>

I have already achieved automated execution using [https://github.com/PierreMarchand20/asciinema\_automation](https://github.com/PierreMarchand20/asciinema_automation).

However, I also want to output some screenshot after running certain commands later.

My initial attempt was:

- Manually writing a list of keywords

- using grep to find the corresponding timestamps in the .cast file

- and then using ffmpeg to extract the frame corresponding to the mp4.

But I strangely found that the duration of the generated gif/mp4 did not match the cast file. (I’m not sure why)

So I changed my approach.

- I slightly modified asciinema\_automation and added a custom command `#mark` inside it. Then, when asciinema\_automation run this instruction, it will try to insert a mark to the .cast file
- Since I cannot directly append to the .cast file while asciinema rec is running, I chose to first record the current file line number like `[42, Mark], [128, AnotherMark]` and then insert them into the .cast file after rec finishes.
- Then I can use agg from this PR [https://github.com/asciinema/agg/pull/103](https://github.com/asciinema/agg/pull/103) to generate beautiful pngs.

For example

```auto
# Compile and run hello.c
gcc hello.c -o hello
./hello

# this is expect from asciinema_automation
#$ expect Hello, World!

#$ wait 500
# insert a mark to .cast file
#mark HelloWorldDone
#$ wait 500

```

Ah, thank you very much to everyone who contributed the work mentioned above
