使用以下命令我可以获得 DBUS 服务列表。
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
输出是:
method return time=1531507472.618646 sender=org.freedesktop.DBus -> destination=:1.83 serial=3 reply_serial=2
array [
string "org.freedesktop.DBus"
string "com.canonical.Unity.Launcher"
string "org.freedesktop.Notifications"
string ":1.7"
string "org.freedesktop.network-manager-applet"
string ":1.8"
string "com.canonical.indicator.datetime"
string ":1.9"
string "org.gnome.Mutter.IdleMonitor"
string "org.gtk.vfs.mountpoint_2434"
string "com.canonical.indicator.sound"
string "org.gtk.vfs.Daemon"
string "org.pulseaudio.Server"
string "com.canonical.indicator.application"
string "com.ubuntu.Upstart"
string "org.gnome.SessionManager"
string "com.canonical.hud"
string "com.canonical.indicator.session"
string ":1.82"
string ":1.60"
string ":1.83"
string ":1.61"
string "com.canonical.indicator.messages"
string "org.gnome.GConf"
string "org.gnome.evolution.dataserver.Sources5"
string "org.gnome.Terminal"
string ":1.63"
string "org.gtk.vfs.UDisks2VolumeMonitor"
string "org.a11y.Bus"
string ":1.64"
string ":1.42"
string ":1.20"
string ":1.65"
string ":1.43"
string "org.gnome.SettingsDaemon.Power"
string ":1.66"
string ":1.44"
string "org.gnome.keyring"
string "org.gnome.Shell"
string ":1.67"
string ":1.45"
string "com.canonical.Unity.WindowStack"
string ":1.68"
string ":1.46"
string ":1.24"
string "com.canonical.Unity.Panel.Service.Desktop"
string ":1.69"
string "org.gnome.DejaDup.Monitor"
string ":1.48"
string ":1.27"
string ":1.28"
string "org.gtk.vfs.GPhoto2VolumeMonitor"
string ":1.29"
string "ca.desrt.dconf"
string "com.canonical.indicator.printers"
string "org.gnome.SettingsDaemon"
string "org.freedesktop.ScreenSaver"
string "org.gnome.evolution.dataserver.Calendar7"
string "org.gnome.SettingsDaemon.XRANDR"
string "org.gtk.vfs.AfcVolumeMonitor"
string "org.ayatana.bamf"
string "org.freedesktop.FileManager1"
string "com.canonical.indicator.bluetooth"
string "org.PulseAudio1"
string "org.gnome.Nautilus"
string "org.gtk.vfs.GoaVolumeMonitor"
string "com.canonical.indicator.keyboard"
string "com.canonical.Unity"
string ":1.70"
string "org.gnome.evolution.dataserver.Subprocess.Backend.Calendarx2320x2"
string ":1.71"
string "org.gnome.evolution.dataserver.Subprocess.Backend.Calendarx2320x3"
string "org.gnome.ScreenSaver"
string "org.gnome.zeitgeist.Engine"
string "org.gnome.evolution.dataserver.AddressBook9"
string ":1.51"
string ":1.74"
string ":1.52"
string ":1.30"
string ":1.75"
string ":1.53"
string ":1.31"
string ":1.76"
string ":1.54"
string "org.gnome.SettingsDaemon.Keyboard"
string ":1.10"
string ":1.77"
string "org.gnome.evolution.dataserver.Subprocess.Backend.AddressBookx2463x2"
string ":1.55"
string ":1.11"
string ":1.33"
string ":1.78"
string ":1.56"
string ":1.12"
string "com.canonical.AppMenu.Registrar"
string ":1.34"
string "org.kde.StatusNotifierWatcher"
string ":1.79"
string ":1.57"
string ":1.0"
string ":1.13"
string ":1.35"
string ":1.58"
string ":1.1"
string ":1.14"
string ":1.36"
string "org.gnome.zeitgeist.datahub"
string ":1.59"
string ":1.37"
string "org.freedesktop.secrets"
string ":1.2"
string ":1.15"
string "org.gtk.vfs.MTPVolumeMonitor"
string ":1.38"
string ":1.3"
string ":1.16"
string "org.gnome.zeitgeist.SimpleIndexer"
string ":1.4"
string ":1.5"
string "org.gnome.Software"
string "com.canonical.indicator.power"
string "org.freedesktop.IBus"
string ":1.6"
]
但我没有看到com.canonical.Unity.Session(或 gnome 的其他)服务。
使用 com.canonical.Unity.Session服务我可以处理屏幕锁定\解锁。我在我的程序中使用它,它将获取解锁屏幕的人的照片。所以目前这个程序只能在该机器上运行,该机器正在使用com.canonical.Unity.Session服务。
问题:如何动态地为我的程序获取服务作为字符串?
附言。文件上的链接,使用 DBUS https://github.com/alkhachatryan/spyonspies/blob/master/autorun.sh