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?
CodePudding user response:
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.
- Bus Name:
org.pwmt.zathura.PID-1057698
- Path:
/org/pwmt/zathura
- Interface:
org.pwmt.zathura
- 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:
- Bus Name:
org.freedesktop.systemd1
- Path:
/org/freedesktop/systemd1
- Interface:
org.freedesktop.systemd1.Manager
- 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"
CodePudding user response:
After wrestling with dbus-send
command, finally I found the right syntax:
dbus-send --session --print-reply \
--dest=org.pwmt.zathura.PID-1057698\
/org/pwmt/zathura \
org.freedesktop.DBus.Properties.Get \
string:org.pwmt.zathura string:numberofpages
The output of that command is:
method return time=1650032068.076028 sender=:1.2273 -> destination=:1.2408 serial=79 reply_serial=2
variant uint32 46
I can use grep to get the value 46
(which is in my case the total number of pages in the PDF document).