You are not logged in.

#1 2022-01-21 12:53:47

xanrer
Member
Registered: 2022-01-04
Posts: 38

[SOLVED] Openbox keybindings can't handle some bash commands.

Hello there, I have been writing an Openbox configuration for the passing few days and I noticed some commands can not be executed when you write them inside rc.xml. I checked their documentation (http://openbox.org/wiki/Help:Actions#Execute) and couldn't find much about my problem. The commands run perfectly under the shell environment. I tested each of them. For example:

    <keybind key="W-A-d">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>notify-send</name>
        </startupnotify>
        <command>notify-send "$(date +%H:%M)" "$(date +%d) $(date +%m) $(date +%Y) - $(date +%A)"</command>
      </action>
    </keybind>

Returns the string "$(date +%H:%M) - $(date +%d) $(date +%m) $(date +%Y) - $(date +%A)" instead of actually giving the time and date.

And these two:

    <keybind key="C-Print">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>maim</name>
        </startupnotify>
        <command>maim -s -u | xclip -selection clipboard -t image/png -i</command>
      </action>
    </keybind>
    <keybind key="W-u">
      <action name="Execute">
        <startupnotify>
          <enabled>true</enabled>
          <name>sh</name>
        </startupnotify>
        <command>sh ; packages="$(yay -Qu | wc -l)";case "$packages" in 0)notify-send "yay" "System is up to Date";;1)notify-send "yay" "1 Package needs update";;*)notify-send "yay" "$packages Packages needs update";;esac</command>
      </action>
    </keybind>

Returns nothing except for making the mouse cursor do the loading sign. I assume Openbox can not handle piping from these two examples, is there a way to make it work? Also before you ask, even after pressing those buttons and restarting Openbox ~/.cache/openbox/openbox.log is empty, so no use there.

Last edited by xanrer (2022-01-21 13:44:47)

Offline

#2 2022-01-21 13:31:14

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,728

Re: [SOLVED] Openbox keybindings can't handle some bash commands.

Please use code tags for pasting outputs: https://bbs.archlinux.org/help.php#bbcode

You use shell constructs while not being in a shell, which the documentation you link mentions is not going to happen. 

Openbox docs wrote:

The "~" tilde character will be expanded to your home directory, but no other shell expansions or scripting syntax may be used in the command unless they are passed to the sh command

Actually execute those with bash e.g.

bash -c 'notify-send "$(date +%H:%M)" "$(date +%d) $(date +%m) $(date +%Y) - $(date +%A)"'

You try it in the last action but the syntax for that would be wrong, you'd use sh -c '$insertlongcommandhere'

Last edited by V1del (2022-01-21 13:49:26)

Offline

#3 2022-01-21 13:47:35

xanrer
Member
Registered: 2022-01-04
Posts: 38

Re: [SOLVED] Openbox keybindings can't handle some bash commands.

Thank you very much! Also, you forgot the last double quote after the command before the single quote. In case someone else wants to try it.

Offline

#4 2022-01-21 13:50:36

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,728

Re: [SOLVED] Openbox keybindings can't handle some bash commands.

Whoops incomplete c'n'p, fixed.

Offline

Board footer

Powered by FluxBB