Search code examples
linuxbashipcgnomedbus

Dbus-send how to get the number of pages from zathura?


I am trying to use dbus-send to get the total number of page from zathura (Zathura is a PDF viewer) (See figure below). I am not familiar with DBus (no matter how I try to learn it, I always give up).

I could use a GUI program to see the total number of pages numberofpages when I double click on that property I get the value.

However, I am trying to get the same information using dbus-send. I tried the following on the terminal:

dbus-send --session --dest=org.pwmt.zathura.PID-1057698 \
 --print-reply org.pwmt.zathura.Properties.numberofpages

The command above doesn't work.

Could you please tell me how can I construct a dbus-command to get the numberofpages value?

enter image description here


Solution

  • This might be easier to do using busctl rather than dbus-send. Either way there is four bits of information you need to know for most D-Bus situation.

    1. Bus Name: org.pwmt.zathura.PID-1057698
    2. Path: /org/pwmt/zathura
    3. Interface: org.pwmt.zathura
    4. Property: numberofpages

    I would expect your situation to look like:

    busctl --user get-property org.pwmt.zathura.PID-1057698 /org/pwmt/zathura org.pwmt.zathura numberofpages 
    

    To try this on a service that is likely to be running on most machines:

    1. Bus Name: org.freedesktop.systemd1
    2. Path: /org/freedesktop/systemd1
    3. Interface: org.freedesktop.systemd1.Manager
    4. Property: Architecture

    And to run it with both utilities:

    dbus-send

    $ dbus-send --session --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.DBus.Properties.Get string:"org.freedesktop.systemd1.Manager" string:"Architecture"
    method return time=1650033765.273653 sender=:1.0 -> destination=:1.176 serial=2677 reply_serial=2
       variant       string "x86-64"
    

    busctl

    $ busctl --user get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager Architecture 
    s "x86-64"