gnome-shellgnome-3screencast

How to start gnome's built in screen recorder via command line?


How to start gnome's built in screen recorder via command line?

I have gone through this post

the command I am using is

gdbus call --session --dest org.gnome.Shell.Screencast --object-path /org/gnome/Shell/Screencast --method org.gnome.Shell.Screencast.Screencast "test_ %d_ %t.webm" "{}"

So it is happening as if screenshot was taken. I mean Screencast is not starting rather it is generating the file with 1sec in this format "test_ %d_ %t.webm"

How can I start recording and stop it with Ctrl+C in the terminal?


Solution

  • I've been looking for this answer for years. Finally stumbled upon following shell-script by Tor Hedin Brønner (hedning)

    Gist: Start gnome shell screen cast from command line

    #!/usr/bin/env nix-shell
    #! nix-shell -i python3 -p python3.pkgs.dbus-python
    
    import dbus
    import time
    bus = dbus.SessionBus()
    obj = bus.get_object("org.gnome.Shell", "/org/gnome/Shell/Screencast")
    
    obj.Screencast("Auto %d %t.webm", [],
                   dbus_interface="org.gnome.Shell.Screencast")
    time.sleep(999999)
    

    💡️ It uses the nix-shell and dbus-python (Python's D-Bus binding) to communicate with GNOME-shell over the D-Bus protocol.

    ✔️ Tested it and it works a treat.