11# nu_plugin_dbus
22
3+ [ Nushell] ( https://nushell.sh/ ) plugin for interacting with [ D-Bus] ( https://dbus.freedesktop.org/ )
4+
5+ With the commands provided by this plugin, you can interact with many of the desktop-oriented
6+ systems on UNIX-like systems that use D-Bus, including Linux and FreeBSD. You can control media
7+ players, on-screen displays, power policies, and even administer services.
8+
9+ Nushell provides a particularly nice environment for interacting with D-Bus, as both support typed
10+ structured data, and interacting with this on a traditional UNIX command line with tools like
11+ ` dbus-send ` and ` busctl ` is cumbersome and tricky to automate.
12+
13+ This plugin automatically determines the correct input types through D-Bus introspection when
14+ available, unlike either of the aforementioned tools, making it easier to interact with objects on
15+ the bus without having to implement boilerplate from documentation.
16+
317## Install with Cargo
418
519Run: ` cargo install --locked nu_plugin_dbus `
@@ -18,49 +32,15 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
1832 Subcommands:
1933 dbus call - Call a method and get its response
2034 dbus get - Get a D-Bus property
21- dbus get-all - Get all D-Bus property for the given objects
35+ dbus get-all - Get all D-Bus properties for the given object
2236 dbus introspect - Introspect a D-Bus object
2337 dbus list - List all available connection names on the bus
24- dbus set - Get all D-Bus property for the given objects
38+ dbus set - Set a D-Bus property
2539
2640 Flags:
2741 -h, --help - Display the help message for this command
2842
29- ## ` dbus introspect `
30-
31- Introspect a D-Bus object
32-
33- Returns information about available nodes, interfaces, methods, signals, and properties on the given object path
34-
35- Search terms: dbus
36-
37- Usage:
38- > dbus introspect {flags} <object>
39-
40- Flags:
41- -h, --help - Display the help message for this command
42- --session - Send to the session message bus (default)
43- --system - Send to the system message bus
44- --started - Send to the bus that started this process, if applicable
45- --bus <String> - Send to the bus server at the given address
46- --peer <String> - Send to a non-bus D-Bus server at the given address. Will not call the Hello method on initialization.
47- --timeout <Duration> - How long to wait for a response
48- --dest (required parameter) <String> - The name of the connection that owns the object
49-
50- Parameters:
51- object <string>: The path to the object to introspect
52-
53- Examples:
54- Look at the MPRIS2 interfaces exposed by Spotify
55- > dbus introspect --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 | explore
56-
57- Get methods exposed by KDE Plasma's on-screen display service
58- > dbus introspect --dest=org.kde.plasmashell /org/kde/osdService | get interfaces | where name == org.kde.osdService | get 0.methods
59-
60- List objects exposed by KWin
61- > dbus introspect --dest=org.kde.KWin / | get children | select name
62-
63- ## ` dbus call `
43+ # ` dbus call `
6444
6545 Call a method and get its response
6646
@@ -92,14 +72,21 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
9272 method <string>: The name of the method to send
9373 ...args <any>: Arguments to send with the method call
9474
75+ Input/output types:
76+ ╭───┬─────────┬────────╮
77+ │ # │ input │ output │
78+ ├───┼─────────┼────────┤
79+ │ 0 │ nothing │ any │
80+ ╰───┴─────────┴────────╯
81+
9582 Examples:
9683 Ping the D-Bus server itself
9784 > dbus call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.Peer Ping
9885
9986 Show a notification on the desktop for 5 seconds
10087 > dbus call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications Notify "Floppy disks" 0 "media-floppy" "Rarely seen" "But sometimes still used" [] {} 5000
10188
102- ## ` dbus get `
89+ # ` dbus get `
10390
10491 Get a D-Bus property
10592
@@ -123,6 +110,13 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
123110 interface <string>: The name of the interface the property belongs to
124111 property <string>: The name of the property to read
125112
113+ Input/output types:
114+ ╭───┬─────────┬────────╮
115+ │ # │ input │ output │
116+ ├───┼─────────┼────────┤
117+ │ 0 │ nothing │ any │
118+ ╰───┴─────────┴────────╯
119+
126120 Examples:
127121 Get the currently playing song in Spotify
128122 > dbus get --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata
@@ -133,9 +127,9 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
133127 │ xesam:url │ https://open.spotify.com/track/51748BvzeeMs4PIdPuyZmv │
134128 ╰──────────────┴───────────────────────────────────────────────────────╯
135129
136- ## ` dbus get-all `
130+ # ` dbus get-all `
137131
138- Get all D-Bus property for the given objects
132+ Get all D-Bus properties for the given object
139133
140134 Search terms: dbus
141135
@@ -156,6 +150,13 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
156150 object <string>: The path to the object to read the property from
157151 interface <string>: The name of the interface the property belongs to
158152
153+ Input/output types:
154+ ╭───┬─────────┬────────╮
155+ │ # │ input │ output │
156+ ├───┼─────────┼────────┤
157+ │ 0 │ nothing │ record │
158+ ╰───┴─────────┴────────╯
159+
159160 Examples:
160161 Get the current player state of Spotify
161162 > dbus get-all --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player
@@ -165,14 +166,16 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
165166 │ PlaybackStatus │ Paused │
166167 ╰────────────────┴────────╯
167168
168- ## ` dbus set `
169+ # ` dbus introspect `
170+
171+ Introspect a D-Bus object
169172
170- Get all D-Bus property for the given objects
173+ Returns information about available nodes, interfaces, methods, signals, and properties on the given object path
171174
172175 Search terms: dbus
173176
174177 Usage:
175- > dbus set {flags} <object> <interface> <property> <value >
178+ > dbus introspect {flags} <object>
176179
177180 Flags:
178181 -h, --help - Display the help message for this command
@@ -182,22 +185,29 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
182185 --bus <String> - Send to the bus server at the given address
183186 --peer <String> - Send to a non-bus D-Bus server at the given address. Will not call the Hello method on initialization.
184187 --timeout <Duration> - How long to wait for a response
185- --signature <String> - Signature of the value to set, in D-Bus format.
186- If not provided, it will be determined from introspection.
187- If --no-introspect is specified and this is not provided, it will be guessed (poorly)
188- --dest (required parameter) <String> - The name of the connection to write the property on
188+ --dest (required parameter) <String> - The name of the connection that owns the object
189189
190190 Parameters:
191- object <string>: The path to the object to write the property on
192- interface <string>: The name of the interface the property belongs to
193- property <string>: The name of the property to write
194- value <any>: The value to write to the property
191+ object <string>: The path to the object to introspect
192+
193+ Input/output types:
194+ ╭───┬─────────┬────────╮
195+ │ # │ input │ output │
196+ ├───┼─────────┼────────┤
197+ │ 0 │ nothing │ record │
198+ ╰───┴─────────┴────────╯
195199
196200 Examples:
197- Set the volume of Spotify to 50%
198- > dbus set --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Volume 0.5
201+ Look at the MPRIS2 interfaces exposed by Spotify
202+ > dbus introspect --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 | explore
199203
200- ## ` dbus list `
204+ Get methods exposed by KDE Plasma's on-screen display service
205+ > dbus introspect --dest=org.kde.plasmashell /org/kde/osdService | get interfaces | where name == org.kde.osdService | get 0.methods
206+
207+ List objects exposed by KWin
208+ > dbus introspect --dest=org.kde.KWin / | get children | select name
209+
210+ # ` dbus list `
201211
202212 List all available connection names on the bus
203213
@@ -220,6 +230,13 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
220230 Parameters:
221231 pattern <string>: An optional glob-like pattern to filter the result by (optional)
222232
233+ Input/output types:
234+ ╭───┬─────────┬──────────────╮
235+ │ # │ input │ output │
236+ ├───┼─────────┼──────────────┤
237+ │ 0 │ nothing │ list<string> │
238+ ╰───┴─────────┴──────────────╯
239+
223240 Examples:
224241 List all names available on the bus
225242 > dbus list
@@ -238,3 +255,43 @@ Then add `register ~/.cargo/bin/nu_plugin_dbus` to your `~/.config/nushell/confi
238255 │ 0 │ org.mpris.MediaPlayer2.spotify │
239256 │ 1 │ org.mpris.MediaPlayer2.kdeconnect.mpris_000001 │
240257 ╰───┴────────────────────────────────────────────────╯
258+
259+ # ` dbus set `
260+
261+ Set a D-Bus property
262+
263+ Search terms: dbus
264+
265+ Usage:
266+ > dbus set {flags} <object> <interface> <property> <value>
267+
268+ Flags:
269+ -h, --help - Display the help message for this command
270+ --session - Send to the session message bus (default)
271+ --system - Send to the system message bus
272+ --started - Send to the bus that started this process, if applicable
273+ --bus <String> - Send to the bus server at the given address
274+ --peer <String> - Send to a non-bus D-Bus server at the given address. Will not call the Hello method on initialization.
275+ --timeout <Duration> - How long to wait for a response
276+ --signature <String> - Signature of the value to set, in D-Bus format.
277+ If not provided, it will be determined from introspection.
278+ If --no-introspect is specified and this is not provided, it will be guessed (poorly)
279+ --dest (required parameter) <String> - The name of the connection to write the property on
280+
281+ Parameters:
282+ object <string>: The path to the object to write the property on
283+ interface <string>: The name of the interface the property belongs to
284+ property <string>: The name of the property to write
285+ value <any>: The value to write to the property
286+
287+ Input/output types:
288+ ╭───┬─────────┬─────────╮
289+ │ # │ input │ output │
290+ ├───┼─────────┼─────────┤
291+ │ 0 │ nothing │ nothing │
292+ ╰───┴─────────┴─────────╯
293+
294+ Examples:
295+ Set the volume of Spotify to 50%
296+ > dbus set --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Volume 0.5
297+
0 commit comments