Difference between revisions of "DBus-usage"
Jump to navigation
Jump to search
(Edit code: grep -Fq will be faster. Notice the actions are flipped) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{See also|DBus|DBus-spec}} | ||
+ | |||
The following is a usage example of how to control VLC though DBUS, by simple using dbus-send. | The following is a usage example of how to control VLC though DBUS, by simple using dbus-send. | ||
This bash script toggles between Play/Pause: | This bash script toggles between Play/Pause: | ||
Line 8: | Line 10: | ||
Pause -> Play | Pause -> Play | ||
− | < | + | <syntaxhighlight lang="bash"> |
#!/bin/bash | #!/bin/bash | ||
− | if | + | if dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep -Fq "int32 2"; then |
+ | # Match found | ||
+ | dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play | ||
+ | else | ||
+ | # Match not found | ||
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause | dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause | ||
− | |||
− | |||
fi | fi | ||
− | </ | + | </syntaxhighlight> |
If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause | If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause | ||
− | < | + | <syntaxhighlight lang="bash"> |
#!/bin/bash | #!/bin/bash | ||
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause | qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause | ||
− | </ | + | </syntaxhighlight> |
− | + | [[Category:Development]] | |
− |
Latest revision as of 04:01, 19 March 2019
The following is a usage example of how to control VLC though DBUS, by simple using dbus-send. This bash script toggles between Play/Pause:
Stopped -> Play
Playing -> Pause
Pause -> Play
#!/bin/bash
if dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.GetStatus | grep -Fq "int32 2"; then
# Match found
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
else
# Match not found
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause
fi
If you have qt-dbus (or libqt4-dev) installed, you can also use qdbus to toggle between Play/Pause
#!/bin/bash
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause