Xfconf-query behaves differently in salt

I am trying to add a keyboard shortcut to xfce using salt.

Here are the files I created:

  • /srv/salt/xfconf.sls
# -*- coding: utf-8 -*-
# vim: set syntax=yaml ts=2 sw=2 sts=2 et :

{% set gui_user = salt['cmd.shell']('groupmems --list --group qubes') %}

add_shortcut:
  cmd.run:
    - name: /usr/local/bin/xfconf_test
    - runas: {{ gui_user }}
  • /usr/local/bin/xfconf_test (mode:755):
#!/usr/bin/env bash

xfconf-query --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Shift>Shift_R" --set xterm --create --type string

Here are the steps I did to reproduce the problem:

  • Execute manually the script:
$ /usr/local/bin/xfconf_test
$ cd ~/.config/xfce4/xfconf/xfce-perchannel-xml
$ grep xterm xfce4-keyboard-shortcuts.xml
      <property name="&lt;Shift&gt;Shift_R" type="string" value="xterm"/> 
  • Press Shift+Shift_R

The shortcut has been saved in the xml file
xfce is aware of the new shortcut
When the shortcut is pressed, an xterm window appears

Let’s bring the shortcuts to its initial state:

  • Open Qubes Application Menu

  • Go to System Settings > Keyboard > Application Shortcuts

  • Remove xterm: Shift+Shift_R

  • Execute the following commands:

$ sudo qubesctl --show-output state.sls xfconf
local:
----------
          ID: add_shortcut
    Function: cmd.run
        Name: /usr/local/bin/xfconf_test
      Result: True
     Comment: Command "/usr/local/bin/xfconf_test" run
     Started: 02:26:56.238803
    Duration: 262.308 ms
     Changes:   
              ----------
              pid:
                  10399
              retcode:
                  0
              stderr:
              stdout:

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time: 262.308 ms
$ grep xterm xfce4-keyboard-shortcuts.xml
  • Press Shift+Shift_R

No shortcut has been saved in the xml file
xfce is not aware of the new shortcut
When the shortcut is pressed, nothing appears
There is no xterm shortcut in System Settings > Keyboard > Application Shortcuts

Questions:

  • Why does xfconf-query behave diffenrently when executed in salt vs manually in a terminal?
  • How do I make xfconf-query work in salt?

N.B. I tried with the xfconf-query command written directly in the .sls file. When I execute qubesctl ..., no shortcut is added.

When using xfconf-query in salt files you need to be provide the current D-Bus session address via the DBUS_SESSION_BUS_ADDRESS environment variable to persist configuration changes. When it is being run non-interactively it does not have direct access to D-Bus session address. So you will need to find the D-Bus address manually by grabbing it from the session running for the current gui user. See below for an updated version of your script that should work correctly.

#!/usr/bin/env bash

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $USER)/bus"

xfconf-query --channel xfce4-keyboard-shortcuts --property "/commands/custom/<Shift>Shift_R" --set xterm --create --type string
1 Like