# Is it possible to "script" asciinema?

**URL:** <https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416>\
**Category:** Help\
**Created:** [August 26, 2020, 6:27pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416 "2020-08-26T18:27:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelmccracken](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/joelmccracken/32/214_2.png) [@joelmccracken](https://discourse.asciinema.org/u/joelmccracken)\
**Post date:** [August 26, 2020, 6:27pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/1 "2020-08-26T18:27:13Z")

</div>

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](https://github.com/joelmccracken/reddup) , 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!

---

<div class="post-metadata">

**Author:** ![ulidtko](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ulidtko/32/178_2.png) [@ulidtko](https://discourse.asciinema.org/u/ulidtko)\
**Post date:** [August 27, 2020, 8:06pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/2 "2020-08-27T20:06:43Z")

</div>

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](https://github.com/cirocosta/asciinema-edit)? 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!

---

<div class="post-metadata">

**Author:** ![joelmccracken](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/joelmccracken/32/214_2.png) [@joelmccracken](https://discourse.asciinema.org/u/joelmccracken)\
**Post date:** [September 29, 2020, 4:52am UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/3 "2020-09-29T04:52:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/asciinema/original/1X/6f3161844cb045ea9769742f3209092edd1b20af.png) [@system](https://discourse.asciinema.org/u/system)\
**Post date:** [June 30, 2021, 11:48pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/4 "2021-06-30T23:48:13Z")

</div>

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:

> **[michaelhenkel/scriptor](https://github.com/michaelhenkel/scriptor)**
>
> Contribute to michaelhenkel/scriptor development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![bcorner13](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/bcorner13/32/305_2.png) [@bcorner13](https://discourse.asciinema.org/u/bcorner13)\
**Post date:** [December 6, 2021, 3:01pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/5 "2021-12-06T15:01:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ku1ik](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ku1ik/32/171_2.png) [@ku1ik](https://discourse.asciinema.org/u/ku1ik)\
**Post date:** [February 6, 2022, 3:29pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/6 "2022-02-06T15:29:06Z")

</div>

Check this out: [Automating terminal demos](https://blog.waleedkhan.name/automating-terminal-demos/)

---

<div class="post-metadata">

**Author:** ![PierreMarchand20](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/pierremarchand20/32/394_2.png) [@PierreMarchand20](https://discourse.asciinema.org/u/PierreMarchand20)\
**Post date:** [August 1, 2022, 2:59pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/7 "2022-08-01T14:59:43Z")

</div>

In case it could be useful, I have made a small python [package](https://github.com/PierreMarchand20/asciinema_automation) 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.

---

<div class="post-metadata">

**Author:** ![zechris](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/zechris/32/399_2.png) [@zechris](https://discourse.asciinema.org/u/zechris)\
**Post date:** [August 4, 2022, 8:04am UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/8 "2022-08-04T08:04:19Z")

</div>

Check out:

- [GitHub - zechris/asciinema-rec\_script: Record 💭 comments and ❯ commands from from shell scripts in addition to their output.](https://github.com/zechris/asciinema-rec_script)

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](https://github.com/asciinema/asciinema#rec-filename) command.

---

<div class="post-metadata">

**Author:** ![zechris](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/zechris/32/399_2.png) [@zechris](https://discourse.asciinema.org/u/zechris)\
**Post date:** [August 4, 2022, 8:11am UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/9 "2022-08-04T08:11:31Z")

</div>

BTW if someone wants to help me package this up into its own container in GitHub’s Container Registry and create a [GitHub Action](https://docs.github.com/en/actions) 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. 😉

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

---

<div class="post-metadata">

**Author:** ![zechris](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/zechris/32/399_2.png) [@zechris](https://discourse.asciinema.org/u/zechris)\
**Post date:** [August 4, 2022, 9:07am UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/10 "2022-08-04T09:07:39Z")

</div>

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…

 ![Screen Shot 2022-08-04 at 19.02.16](https://canada1.discourse-cdn.com/flex027/uploads/asciinema/original/1X/bb1e4cf92c2f908df75547187245229ae338f1c0.png)

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:

- [foo.sh - asciinema](https://asciinema.org/a/0n0aeKFZGFuElsR7RgmAAWx6b)

---

<div class="post-metadata">

**Author:** ![ku1ik](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ku1ik/32/171_2.png) [@ku1ik](https://discourse.asciinema.org/u/ku1ik)\
**Post date:** [January 24, 2024, 9:12am UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/11 "2024-01-24T09:12:32Z")

</div>

For anyone looking into this in the future: check out the list of integrations: [Integrations - asciinema docs](https://docs.asciinema.org/integrations/)

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

---

<div class="post-metadata">

**Author:** ![ofek](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ofek/32/506_2.png) [@ofek](https://discourse.asciinema.org/u/ofek)\
**Post date:** [May 1, 2024, 10:37pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/12 "2024-05-01T22:37:28Z")

</div>

You might like what I just released: [Docker container for producing GIF files of shell sessions](https://discourse.asciinema.org/t/docker-container-for-producing-gif-files-of-shell-sessions/818)

---

<div class="post-metadata">

**Author:** ![ku1ik](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ku1ik/32/171_2.png) [@ku1ik](https://discourse.asciinema.org/u/ku1ik)\
**Post date:** [January 30, 2025, 8:39pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/13 "2025-01-30T20:39:58Z")

</div>

In the topic of scripting the recording, I’m thinking of implementing an RPC mechanism for `asciinema rec`, which would allow controlling the recording session (including the input) programmatically. It could be controlled for example via a UNIX socket or via STDIN (when recording in headless mode).

Does that sound useful?

---

<div class="post-metadata">

**Author:** ![joelmccracken](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/joelmccracken/32/214_2.png) [@joelmccracken](https://discourse.asciinema.org/u/joelmccracken)\
**Post date:** [January 31, 2025, 6:51pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/14 "2025-01-31T18:51:47Z")

</div>

I guess I forgot to reply to all of your helpful suggestions, my apologies. I haven’t revisited this sub-task since I posted. I’m not sure which/any of these will work for me, but they all sound interesting. I’m probably going to want to try it for a project that i’m working on now (tho not the one I posted on ages back)

the ideal solution to me would be a sort of text based “script” that drives interaction, it would just take stdin/stdout from a process, and then generate a “fake” terminal session with it. And then, most ideally, it could be updated automatically via CI.

I _think_ this would likely be achievable with something like expect, tho its painful, but some kind of automatic solution for like user-like typing speeds, some pausing between command results and next command, etc.

Sending commands via RPC would be perfect as an implementation mechanism, I think.

---

<div class="post-metadata">

**Author:** ![balupton](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/balupton/32/472_2.png) [@balupton](https://discourse.asciinema.org/u/balupton)\
**Post date:** [February 3, 2025, 10:11pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/15 "2025-02-03T22:11:30Z")

</div>

In [dorothy](https://github.com/bevry/dorothy) we automate inputs in our tests like so:

```bash
	{
		sleep "$delay"
		__print_string "$down" # down to second preference
		sleep "$delay"
		__print_string "$enter" # select second preference
		sleep "$delay"
		__print_string "$escape" # cancel the confirmation of second preference
		sleep "$delay"
		__print_string "$enter" # change mind, do select second preference
		sleep "$delay"
		__print_string "$enter" # confirm second preference
	} | eval-tester --name='select second preference then cancel that, select second preference then confirm that' --stdout='c' \
		-- choose 'q' 'd' --confirm --required --default=b --default=c --default=d -- a b c d

```

I’m considering redoing our `echo-style` command to support input characters, such that that would become:

```bash

	export ECHO_STYLE__DEFAULT_SLEEP="$delay"
	echo-style --sleep+down --sleep+enter --sleep+escape --sleep+enter --sleep+enter | \
	eval-tester --name='select second preference then cancel that, select second preference then confirm that' --stdout='c' \
		-- choose 'q' 'd' --confirm --required --default=b --default=c --default=d -- a b c d

```

For sending inputs to asciinema, this could become:

```bash
echo-style --sleep+down --sleep+enter --sleep+escape --sleep+enter --sleep+enter | \
asciinema rec --stdin

# or even something like this
export ECHO_STYLE__PRINT_DELAY="$delay"
echo-style --down --enter --escape --enter --enter | \
asciinema rec --stdin 

```

Let me know if that would be of interest.

However, I think that [my suggestion of a `asciinema replay <cast>`](https://discourse.asciinema.org/t/using-asciinema-for-testing/923) would be a suitable alternative to this need though.

---

<div class="post-metadata">

**Author:** ![joelmccracken](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/joelmccracken/32/214_2.png) [@joelmccracken](https://discourse.asciinema.org/u/joelmccracken)\
**Post date:** [February 3, 2025, 11:21pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/16 "2025-02-03T23:21:09Z")

</div>

ooo, TIL about dorothy. It seems quite in spirit with the thing i’ve been working on for a while. Looks cool, I’ll probably use it with the thing I’m working on.

(Oh and thank you for that, it will be easier to adapt working code for sure)

Edit: I’ve been considering working on a way to write a kind of `expect` in bash, which would have to end up using coproc. Which seems quite similar.

(a while back I tried learning TCL for expect usage and struggled to make sense of things, so I don’t want to use that directly)

---

<div class="post-metadata">

**Author:** ![russoz](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/russoz/32/629_2.png) [@russoz](https://discourse.asciinema.org/u/russoz)\
**Post date:** [June 17, 2025, 11:36pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/17 "2025-06-17T23:36:47Z")

</div>

Hi @joelmccracken I have just announced “asciinwriter” ([Yet another tool to generate input - #3 by russoz](https://discourse.asciinema.org/t/yet-another-tool-to-generate-input/1009/3)) that serves exactly that purpose. I wanted to script the term demo of my project.

It consumes an input like:

```auto
  SEND(git clone --quiet --depth 1 https://github.com/ansible-collections/community.general.git)
 ENTER()
EXPECT($ )

  SEND(cd community.general)
 ENTER()
EXPECT($ )
  SEND(ls)
 ENTER()
EXPECT($ )

  SEND(andebox test -R -- integration --docker default --python 3.13 pipx_info)
 ENTER()
EXPECT($ )

```

In fact, since you mentioned `expect`, this one is based on `expect` (or more precisely `pexpect`, the Python implementation of if).

---

<div class="post-metadata">

**Author:** ![rugk](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/rugk/32/669_2.png) [@rugk](https://discourse.asciinema.org/u/rugk)\
**Post date:** [November 27, 2025, 9:43pm UTC](https://discourse.asciinema.org/t/is-it-possible-to-script-asciinema/416/18 "2025-11-27T21:43:51Z")

</div>

[Stackoverflow also has a list of tools BTW](https://stackoverflow.com/q/53969566/5008962).

I once also stumbled upon [Autocast](https://github.com/k9withabone/autocast) – fix this and all folowing link when I have enough permissions-- and it also has a YAML playbook which you can run to automate it away.

Another alternative approach being [used here is asciinema for recording] (hxxps://github.com/borgbackup/borg/pull/6197) is [TCL/TCL Expect] (hxxps://core.tcl-lang.org/expect/index) and (optionally, I guess isolating this via docker or Vagrant.

[Reference to where I proposed this.] (hxxps://github.com/borgbackup/borg/issues/8040)
