如何在dbus信号上运行脚本?

是否可以在任意dbus信号上运行脚本? 像Upstart这样以非特权用户身份运行并且不需要root权限进行修改的东西?

我问,因为我已经写了一个愚蠢的脚本, 等待蓝牙事件启动我的音乐播放器 。 现在,当我的机器连接到特定网络或其他设备时,我想做类似的事情。

编辑:我的原始问题没有指定这个,但我的意思是“将一些脚本与一组事件中的一个相关联” – 所以我有同样的启动器(如Upstart)来管理许多脚本,每个都关心不同的dbus信号。 全部在用户空间。

你需要dbus-monitor

该脚本看起来像

 #!/bin/bash interface=org.gnome.Rhythmbox.Player member=playingUriChanged # listen for playingUriChanged DBus events, # each time we enter the loop, we just got an event # so handle the event, eg by printing the artist and title # see rhythmbox-client --print-playing-format for more output options dbus-monitor --profile "interface='$interface',member='$member'" | while read -r line; do printf "Now playing: " rhythmbox-client --print-playing done 

取自https://stackoverflow.com/a/5345462/854477