2

I want to use Gnome's inbuilt Screen Recorder. I know that I can Launch it using the keyboard shortcut Ctrl+Shift+Alt+R. I am looking for options to start the gnome screen recorder using some command so I can automate it in script. Please help.

2 Answers 2

1

The screen recorder is accessible via D-Bus at the bus name org.gnome.Shell.Screencast, and provides a control object /org/gnome/Shell/Screencast. Looking at it through d-feet, these are the available methods:

  • Screencast(Str file_template, Dict{Str,Var} options) → (Bool success, Str filename_used)
  • StopScreencast() → (Bool success)

The parameter file_template is either a full path or just the base filename of the video file (which needs to have a .webm extension either way). The options dict can remain empty.

Unfortunately, the screencasting sessions are tied to a specific D-Bus client – so you cannot use them through usual shellscript tools (busctl, gdbus, dbus-send) as the recording would stop as soon as the tool starts it and exits. So you'll have to write a wrapper in some other language which has native D-Bus client bindings.

1
  • Thank you for the answer. Unfortunately I am not sure how to achieve my requirement with your suggestion. However, I was able to achieve it using a different method, using xdtool. I created a file with content xdtool key Alt+Shift+Ctrl+R and when this file is executed, it will start/stop screen recording. Note: Later I noticed, it is not working perfectly, may be the script is not able to replicate the effect of four simultaneous key presses.So I changed the Shortcut as "Alt+U" and then changed the file as below. xdtool key Alt+U And it is working without any issues so far.
    – Sajeesh
    Commented Oct 19, 2018 at 8:05
0
import time
import dbus
session_bus = dbus.SessionBus()
session_bus.call_blocking(
    'org.gnome.Shell.Screencast',
    '/org/gnome/Shell/Screencast',
    'org.gnome.Shell.Screencast',
    'Screencast',
    signature='sa{sv}',
    args=["Screencast_%d_%t.webm", {'draw-cursor':True, 'framerate': 35}],
)

time.sleep(5)

result2 = session_bus.call_blocking(
    'org.gnome.Shell.Screencast',
    '/org/gnome/Shell/Screencast',
    'org.gnome.Shell.Screencast',
    'StopScreencast',
    signature='',
    args=[],
)

$ gdbus call --session --dest org.gnome.Shell.Screencast --object-path /org/gnome/Shell/Screencast --method org.gnome.Shell.Screencast.Screencast "Screencast_%d_%t.webm" "{'draw-cursor':<'true'>,'framerate': <35>}"
$ # "The screencast is stopped here, the command below is meaningless.'
$ gdbus call --session --dest org.gnome.Shell.Screencast --object-path /org/gnome/Shell/Screencast --method org.gnome.Shell.Screencast.StopScreencast

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .