Is it possible to "script" asciinema?

So something I’ve always wanted is the ability to “script” a video, so that all i have to do is edit the script file then regenerate the video.

I think I could hack this together by using shell-mode in emacs and then writing elisp to send commands to it. But, has anyone else done something like this?

An example, I have a project GitHub - joelmccracken/reddup: Helping you keep your workstation nice and tidy , and i get a lot of people who don’t quite “get” why the project would be useful. So I thought having a screencast would be a great way to “demo”. Basically, if I could script it, what I would do is something like:

cd to some directory
run a bunch of git and touch commands to set up a repo in a certain way.
start asciinema
run my project (and script the way it should interact)
stop asciinema.

I hope that is clear. The big value would be in having a repeatable “setup” and it would be a lot easier to add and remove demo features.

Thanks!

Well yes, pretty easy. Maybe even easier than you think!

The --command= option allows to specify the program you run, it’s $SHELL by default. Just set it to whatever program you can script in which will literally output the “movie” to its stdout! Then you get the scriptability from the program (oh I guess it’ll be rich in sleep() calls), as well as the preserved recording from asciinema. That’s Unix-style program composition!

Too bad you can’t really edit the recordings… Or can you? However there’s also asciinema rec --stdin mode, which’ll record your manual timed input into the replayable file.

I hope, some combination of these would become useful!

2 Likes

Thank you! and sorry for the belated reply. I think I’m going to start working on this soon. WOuld you be interested in hearing what I come up with?

2 Likes

not sure if it is still a topic but I created a small golang based tool which allows to script the sequence by defining a couple of parameters such as character typing speed:

there is an opensource tool called asciinema-edit. Take a look at it to see if its what you want.

Check this out: Automating terminal demos

In case it could be useful, I have made a small python package to automate recordings. It uses pexpect, so it is similar to what is used in the blog post @ku1ik pointed out in his answer in some sense.

Check out:

This is done by building a version of the original script that surfaces all the comments and commands by also echoing them to the screen.

Then passing that augmented script to asciinema’s rec --command command.

BTW if someone wants to help me package this up into its own container in GitHub’s Container Registry and create a GitHub Action from it to regenerate screencasts from a set of shell scripts in a screencasts directory.
ie. after every merge to main in any repo using it in a github action

I’m sure it would be super popular. :wink:

(I tried but couldn’t get it working.)

Getting back to @joelmccracken 's original question…
Here’s how you’d use asciinema-rec_script to turn a simple bash script into a useful screencast…

Nb. I didn’t attempt making a screen recording of creating a screen recording - hence the screenshot.

But here’s a link to the resulting screencast:

For anyone looking into this in the future: check out the list of integrations: Integrations - asciinema docs

Some of them help with scripting and/or generating recordings automatically.